Re: Memory Management
Re: Memory Management
- Subject: Re: Memory Management
- From: Nat! <email@hidden>
- Date: Thu, 31 Jul 2003 00:32:36 +0200
Am Mittwoch, 30.07.03 um 10:12 Uhr schrieb Nat!:
Am Mittwoch, 30.07.03 um 01:13 Uhr schrieb John Randolph:
On Tuesday, July 29, 2003, at 11:23 AM, Nat! wrote:
Autorelease pools have some clear semantics. Every object added to
an autorelease pool gains a property, a guaranteed minimum lifetime.
Umm, no.
An object added to an autorelease pool is going to get a -release
message whenever the pool gets released, and that's all. The act of
adding it to the pool has no effect of guaranteeing a minimum >
lifetime.
-jcr
ok, I should have explicitily stated the assumption that the object is
added retained.
But with my answer I am obscuring my own point, that adding it retained
to the pool does guarantee a minimum lifetime. As John states "An
object added to an autorelease pool is going to get a -release message
whenever the pool gets released". That's exactly the minimum lifetime.
It can be longer, but it can't be less.
And adding it non-retained and not crashing is a trick you must show me
as
s = [[NSString alloc] initWithFormat:@"My retain count is 1"]
[s autorelease]; // yes its retained
[s release]; // bad idea
In this example ownership is transferred to the autorelease pool. s can
not die earlier than the enclosing autorelease pool.
As an example:
s = [[NSString alloc] initWithFormat:@"foo"];
this says, the object lives as long as it isn't freed. You must know
your code to determine if s is still valid at a certain point in your
code or not.
s = [[NSString alloc] initWithFormat:@"foo"];
[s autorelease];
this says, the object lives at least as long as the autorelease pool
exists. (Someone may retain it, but that's OK)
The fact that you should have a good idea when your autorelease pool
dies make this less obscure, in fact you can avoid thinking about it in
many cases.
I would like to see someone prove to me in working code, that adding an
object to an autorelease pool does not guarantee that it will live at
least until the pool is purged.
Ciao
Nat!
------------------------------------------------------
The idea was to offend people. But not just with
garbage. Just because something is offensive crap
doesn't necessarily mean it's any good. - Philip Dick
_______________________________________________
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.