Re: Autorelease/Retain/Release
Re: Autorelease/Retain/Release
- Subject: Re: Autorelease/Retain/Release
- From: Michael Watson <email@hidden>
- Date: Wed, 25 Jul 2007 00:27:50 -0400
Yet another back-and-forth over Cocoa memory management. You know,
guys, there's a reason that the following is in the monthly list
guidelines post:
Developers are strongly discouraged from attempting to reformulate
Cocoa's memory management rules in posts to the list. Almost
invariably, someone makes a subtle or not-so-subtle mistake which
then results in confusion and additional messages to resolve the
issue. Simply post links to the relevant documentation, such as:
<http://developer.apple.com/documentation/Cocoa/Conceptual/
MemoryMgmt/Tasks/MemoryManagementRules.html>
Links to other reviewed articles that discuss memory management are
given in <http://www.alastairs-place.net/cocoa/faq.txt>
--
m-s
On 24 Jul, 2007, at 23:22, Charlton Wilbur wrote:
On Jul 24, 2007, at 11:01 PM, mmalc crawford wrote:
On Jul 24, 2007, at 7:18 PM, Tim Davis wrote:
As Charlton put it, the autorelease pool is sometimes quirky as
to when it actually gets rid of objects, so I would actually be
better off releasing it myself, and keeping the autorelease uses
to things like looping through an XML doc or creating one (in
this example anyways).
No, this is not correct.
The autorelease pool is *not* quirky as to when it actually gets
rid of objects; it sends a release message to all objects that
have been autoreleased within its scope when it is itself
released. That's it. There is no "quirkiness".
I did not say it was quirky; I said that the memory management
contract in Cocoa is that the autorelease pool releases its objects
"at some point in the future," not "when the current block finishes
execution." If you created an autorelease pool, you control when
it sends the release messages, but if you're using another
autorelease pool, it depends on where the autorelease pool comes from.
It's not hard to envision an autorelease pool optimization in a
framework where the release message is only sent if there are a
certain number of objects in the pool, though whether it would
actually provide a performance increase is doubtful; and if there's
no Cocoa event loop, such as in a shell tool, there may be a single
autorelease pool that's created at the start of the program and
released at the end; code that uses autorelease, such as classes
that may be called as part of a shell tool or as part of a Cocoa
application shouldn't make assumptions about when the objects are
released, because there's no guarantee in the contract.
This is not "quirkiness"; this is "the contract only guarantees
what the contract actually guarantees."
Charlton
--
Charlton Wilbur
email@hidden
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40bungie.org
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden