• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: simple array release error question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple array release error question


  • Subject: Re: simple array release error question
  • From: Shawn Erickson <email@hidden>
  • Date: Sat, 31 May 2003 18:29:15 -0700

On Saturday, May 31, 2003, at 04:41 PM, Ben Dougall wrote:

On Sunday, June 1, 2003, at 12:32 am, sinclair44 wrote:

The first example does not suffer from this problem because the array no
longer references the objects when you release it, because they are removed
from the array's internal list when you call -removeAllObjects.

i see: with the second version, because the objects were released *via* the array rather than behind it's back as it were, so therefore it knows, hence no problem. ok, thanks-a-lot.

I am not sure if you fully get the point...

Doing the following is perfectly ok but only if you had alloc-ed, copied, or retained the items you put in the array. (also it is better ask the array how many items it has)

for(i = 9; i >= 0; i--)
[[array objectAtIndex:i] release];

In your code snippet you did not list how the things you are putting into the array got created. They are most likely being created for you by something else and hence you are getting an object that is already in the autorelease pool. So you are not responsible for getting them deallocated.

Also you don't need to empty the array before releasing the array, when the array gets deallocated (its retain count reaches zero) it will automatically send a release message to every object it contains.

-Shawn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: A slightly trickier NSView problem
  • Next by Date: Pipe
  • Previous by thread: Re: simple array release error question
  • Next by thread: A slightly trickier NSView problem
  • Index(es):
    • Date
    • Thread