• 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: I think I get it
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I think I get it


  • Subject: Re: I think I get it
  • From: j o a r <email@hidden>
  • Date: Mon, 5 May 2003 11:29:17 +0200

On Monday, May 5, 2003, at 11:07 Europe/Stockholm, Danny Swarzman wrote:

When the number of calls to release reaches the number of calls to retain
plus one for an object, the memory allocated to the object is released.

Almost true, you should have said "...the object is deallocated / freed" to use a more correct nomenclature. Retain-release is part of the reference counting mechanism, alloc-dealloc is part of the actual creation-destruction of objects.

A call to autorelease has the same effect as a call to release except that
the memory persists between the time of the call to autorelease and the
next cycle of the event loop.

Mostly true.

Autoreleased objects are added to the innermost autorelease pool, and released when the pool they are added to is deallocated. In the general case you use the default autorelease pool created for you at the beginning of the event loop and destroyed at the end of the event loop. In this case your statement is true.
In some cases however you need to manage your own autorelease pools, and in these cases also manage their destruction - like you would any other object you create. When you manage your own autorelease pool, you decide when it is deallocated, and hence when it's contained objects are sent the delayed release message.

Equivalent to invoking autorelease in C would be to call release at the end
of A for the object. That is if you assume that A is at the top level of
the methods invoked in the event loop. Invoking autorelease in C avoids
clutter and makes the program easier to write.

Notice that this is also an very important optimization - optimizing for readability and maintainability!

j o a r
_______________________________________________
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: 
 >I think I get it (From: Danny Swarzman <email@hidden>)

  • Prev by Date: I think I get it
  • Next by Date: Window group hierarchy
  • Previous by thread: I think I get it
  • Next by thread: Re: I think I get it
  • Index(es):
    • Date
    • Thread