Re: Newbie question: how to release an object that has been autoreleased
Re: Newbie question: how to release an object that has been autoreleased
- Subject: Re: Newbie question: how to release an object that has been autoreleased
- From: mmalcolm crawford <email@hidden>
- Date: Wed, 22 Sep 2004 11:25:09 -0700
On Sep 22, 2004, at 8:03 AM, James Bucanek wrote:
Ondra Cada wrote on Wednesday, September 22, 2004:
Uh, sorry, but I beg to differ: IMHO, the following pattern is not
that
good.
On 22.9.2004, at 9:29, mmalcolm crawford wrote:
Buffer *bufferFromPool = [Buffer newBufferFromPool];
// ...
[bufferFromPool release];
? No autorelease "issues," and more efficient.
Also considerably more prone to programmer's errors of the new/release
mismatch kind, which is pretty bad. And also prone to leak if an
exception is raised.
We'll have to agree to differ on this, then...
Here's another good reason why this won't work: I can't call the
Buffer constructor directly.
The message that creates the Buffer object is a factory method, which
creates any of several sub-classes of Buffer depending on the type of
the pool. The type information, and the variables needed to
initialize the Buffer object, are private to the Pool object. To
allow the client to create the Buffer objects directly would destroy
my encapsulation.
It's again not clear why this won't work.
'newBufferFromPool' is exactly the same as your original
'bufferFromPool' except that it doesn't autorelease the returned value.
Moreover, alloc/init is perfectly capable of doing initialisation etc.,
even returning an instance of a different class (see NSArray et al.).
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden