create an autorelease pool in the init-method and release it in the dealloc-method ..?
create an autorelease pool in the init-method and release it in the dealloc-method ..?
- Subject: create an autorelease pool in the init-method and release it in the dealloc-method ..?
- From: Martin Batholdy <email@hidden>
- Date: Sun, 15 May 2011 01:43:33 +0200
Hi,
I still have trouble understanding the autorelease pool.
Lets assume an object Z has a method where it gets a string y and returns another string x.
Now when an instance of this object is created and the method is invoked,
x is returned and is used somewhere else.
Now this method of object Z should not be the owner of x right?
Because x is used elsewhere.
So I add x to the autorelease-pool to declare that I am not the owner (and won't send it a release message);
x = [[[NSString alloc] init] autorelease];
but where do I release the pool?
And to which pool is it added?
I thought I would create my own pool in the init-method of Z and send it a [pool release] message in the alloc-method.
But I haven't seen that so far in sample code ...
can someone explain me what happens when I add x to the autorelease pool?
And where does it get released when I don't send a release command to the pool?
_______________________________________________
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