• 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: retain and autorelease
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: retain and autorelease


  • Subject: Re: retain and autorelease
  • From: Public Look <email@hidden>
  • Date: Fri, 14 Nov 2003 17:27:18 -0500

Autoreleased objects are not released by an autorelease pool until the pool is deallocated. This is not that complicated or that confusing. There is no magic involved. There is no uncertainty or ambiguity.

An autorelease pool is just a container (like an array). When an object is autoreleased, a reference to the object is stored in the current autorelead pool. At a later time, the autorelease pool is deallocated and it releases all of the objects to which it stores references. The objects will only be deallocated if the release caused by the autorelease pool decrements the object's retain count to zero. The same object can safely be referenced any number of times in any number of autorelease pools.

The autorelease pools created by the application kit are not deallocated until just before the next event is processed. Unless you are using third party frameworks that do starnge things, any autorelease pools other than the ones created by the application kit are explicitly created by your program, and you have complete control over when they are deallcated.

On Nov 14, 2003, at 4:26 PM, Ben Dougall wrote:

On Thursday, November 13, 2003, at 11:29 pm, Shawn Erickson wrote:

On Nov 12, 2003, at 7:25 PM, Darwin Zins wrote:

When I do this:

ABPerson * newMacABEntry;
newMacABEntry = (ABPerson *) [_macAddressBook recordForUniqueId:
abID ];

Should I then do: [newMacABEntry retain]; and when I am done with it
[newMacABEntry autorelease];

It depends on what you are doing. In general if you are not using the entry outside of the method you are currently in then you need not retain it. It will remain for your use while inside of your method, assuming you (or possibly someone else) do nothing to get it released earlier.

that's something i've never been sure on - the lifetime of an unretained object like that. you say it'll probably hang round until the end of the current method - what about if there's a method call inbetween the above non retained convenience creation and the end of the current method? even a simple presumably short/quick method call like adding an object to an array for exmaple? that takes the thread elsewhere, out of the current method. would it still be ok not to retain do you think?

just wondering. thanks.
_______________________________________________
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.
_______________________________________________
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.

References: 
 >Re: retain and autorelease (From: Ben Dougall <email@hidden>)

  • Prev by Date: Re: retain and autorelease
  • Next by Date: Re: retain and autorelease
  • Previous by thread: Re: retain and autorelease
  • Next by thread: Re: retain and autorelease
  • Index(es):
    • Date
    • Thread