Re: More memory allocation questions
Re: More memory allocation questions
- Subject: Re: More memory allocation questions
- From: Marcel Weiher <email@hidden>
- Date: Mon, 29 Jul 2002 12:16:42 +0200
On Monday, July 29, 2002, at 03:07 Uhr, Terry Simons wrote:
At the end of the event loop,
Sort of yes, but only because of the above, and only if you don't
have any nested pools. It is not a general feature of autorelease
pools, just that Cocoa sets up some autorelease pools that way.
Right, I wasn't thinking about that, but the stepwise docs talk about
nested pools, and setting up your own pools.
I was thinking in the more general sense the allocation pool that is
set up for you with the "standard" apps that I've been working with.
But that's not the more general sense, but the more *specific* sense.
There is a general way that autorelease pools work. If you understand
that, the specific way it is set up in Cocoa is no problem.
so that if they are in the autorelease pool when you get access to
them, you can make sure they stay around until you're done with >>> them.
This has nothing to do with autorelease pools. Please don't make it
more complicated than necessary.
You want to keep it, you send it retain. That's it.
Right. I should have something more like... "Sending a retain or a
copy guarantees that the object will be around for you until you
release it, unless someone mistakenly sends more release or
autorelease messages than they should to the object."
The allocation pools are *only* used by autorelease, right?
I am not quite sure what you mean here. Yes, of course.
Autorelease-Pools (there are no allocation pools) are the
implementation mechanism for autorelease.
If you retain an object, then you should release/autorelease it.
You should release it at some time. (Autoreleasing is nothing more
than releasing a little later).
Right, but the autorelease mechanism deals with allocation pools,
whereas release directly fiddles with the counter, and once it hits 0,
the object gets dealloc'd.
Yes, but this is irrelevant at that point. If you retain an object,
you must relase it. Autorelease is nothing more than sending the
release a little later.
Autorelease does nothing other than put the object in the pool, and
that object eventually gets sent a release.
Exactly. In the context of the rule of balancing your retains and
releases, how autorelease works is completely irrelevant. All you have
to concern yourself with is that it will send a release later.
The thing to care about is that the object will eventually get it's
counter decremented, in the hopes that everyone did everything
correctly, and the counter will hit zero, and be deallocated.
Exactly.
For all intents and purposes it's enough to know that your object
"will be released at a future date".
For the intents and purposes of balancing your retains and releases.
If you don't autorelease/release objects that you create with
alloc/init then you'll leak memory.
If you don't release. Autorelease is just a release that happens
later.
Yes... but both release and autorelease eventually end up doing the
same thing.
Exactly. Since an -autorelease ist just a way of sending a -release,
you don't have to explicitly mention it.
My point was that you need to make sure to release or autorelease
No, you just have to make sure you release. Sending an autorelease
message is just one way of making sure you send a -release message.
An autorelease is just an eventual release,
Exactly.
but it serves the same purpose in a broad scope.
No "but" here. It is just a different way of sending a -release,
therefore there is no need to mention it separately.
An autorelease just happens "later" and all we really care about is
that we released our dominance over the object so to speak.
We let go of our reference...
The one example that keeps floating through my mind is the one where
you might want to return an object that you've created, and so you use
an autorelease in that case, as opposed to a release, because if you
simply release it, then it will be invalidated before the user can
retain it.
That is exactly why autorelease was invented.
In other reference counting schemes (without autorelease), you must
always decrease the reference count of an object that you got, leading
to loads of unnecessary refcount operations.
Marcel
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
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.