Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8406993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:15:59+00:00 2026-06-09T23:15:59+00:00

Say I have an NSMutableArray *sasquatch that has some arrays in it. In ARC,

  • 0

Say I have an NSMutableArray *sasquatch that has some arrays in it.

In ARC, if I call [sasquatch removeAllObjects]; does this cause all the arrays in the sasquatch array to be nil? So that the objects in the arrays of the sasquatch array are also all removed too and dealloced and stuff?

Because I don’t know if I should do this:

 for (NSArray *animalPlanetSearchingFor in sasquatch){
[animalPlanetSearchingFor removeAllObjects];
}

before I call [sasquatch removeAllObjects];

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:16:00+00:00Added an answer on June 9, 2026 at 11:16 pm

    it won’t recursively empty all arrays — it will decrement their ref counts when removed. when the ref count of an array is 0, all objects are removed. they clean up after themselves.

    iow, sasquatch‘s sub-arrays are not changed — with one exception: if sasquatch held the last reference to that sub-array. in that case, the element (sasquatch’s sub-array) will be deallocated.

    In ARC, if I call [sasquatch removeAllObjects]; does this cause all the arrays in the sasquatch array to be nil?

    Well, it just sends release to each element an changes the count (etc.). NSArrays can’t hold nil elements — it is forbidden.

    So if you make a copy of the array – then a reference to the sub-arrays will be added, and you would extend the sub-arrays’ lifetimes because a reference is now held by the copy as well.

    So that the objects in the arrays of the sasquatch array are also all removed too and dealloced and stuff?

    The sub-arrays will be deallocated at that time if sasquatch held the last reference. Remember that references may also exist in autorelease pools so your order of destruction is not explicitly defined — even in the simplest case.

    Another way to look at it: Everything in sasquatch and its sub-arrays (recursively) will be destroyed when the last reference of it is lost — only if every element is the last held reference.

    In short — there is no need to call removeAllElements in either case for the purpose of cleanup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a class Car that has 2 properties: NSMutableArray *parts and BOOL
Say I have a tableview class that lists 100 Foo objects. It has: @property
I have two simple NSMutableArray that consists of few objects. Some of these objects
OK so I know that dictionaries can't be sorted. But, say I have NSMutableArray
I'm having a hard time getting the hang of this. Say I have: NSMutableArray
I have three array..say array1,array2,array3. All these arrays contains dictionary.Now, I want to copy
Lets say have this immutable record type: public class Record { public Record(int x,
Say I have a SSI script that uses exec, or a PHP script that
Say I have this: private list<myClass> myCollection; Is there a programming idiom to shorten
Say I have NSMutableArray *array1 with 10 objects. I want to create an *array2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.