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: Scott Stevenson <email@hidden>
- Date: Tue, 21 Sep 2004 23:58:34 -0700
On Sep 21, 2004, at 8:31 PM, James Bucanek wrote:
I'm fairly new to Cacoa programming and am in the process of creating
my first major application. I've got a few basic memory management
questions that I can't seemed to find the answers to in the
documentation.
Second question: I have an object that has been init'd then
autoreleased. How do I destroy it immediately?
Example:
I have a pool of buffers. One message in that buffer pool creates a
new buffer object. Like a good Cocoa programmer, I autorelease the
object before I return it.
- (Buffer*)bufferFromPool
{
return ( [[[Buffer alloc] initWithMagic] autorelease] );
}
The client code uses the buffer, but now I want to destroy it
immediately after I'm done with it. I can't release it because it's
already been autoreleased.
Why do you need it released immediately? The fact that you're running
into this at all suggests you're making things more complicated than
they need to be.
If it's that important, just ignore the rule and don't return it
autoreleased. It would be a good idea to make this clear in the method
name (retainedBufferFromPool perhaps). But it would be far better to
create a situation where you can let autorelease do its thing normally.
- Scott
--
Tree House Ideas
http://treehouseideas.com/
_______________________________________________
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