Re: Autorelease pool
Re: Autorelease pool
- Subject: Re: Autorelease pool
- From: Negm-Awad Amin <email@hidden>
- Date: Thu, 8 Oct 2009 16:35:19 +0200
Am Do.,08.10.2009 um 16:36 schrieb Michael Süssner:
Hi ,
thanks a lot for your tips. after having read the bible and some
experiments I have learned how to do it correctly.
Here the conclusion for the rest of the world:
NSMutableArray *vPolyArray = [[NSMutableArray alloc]
initWithCapacity:6];
vPolygon = [[[PolygonShape alloc] initWithNumberOfSides:5
minimumNumberOfSides:2 maximumNumberOfSides:8] autorelease];
[vPolyArray addObject:vPolygon]; // now only the Array is the owner
of the object
...
Hopefully the … contains no exception, no return and no break (if you
are in a loop).
[vPolyArray autorelease]; // since I have created the array with
alloc and init I have to release it or autorelease it
Thanks a lot
g
Michael
On Oct 7, 2009, at 2:53 PM, Michael Süssner wrote:
After my test program has passed successfully the drain method of
the autorelease buffer is called and "sometimes" I get the
following error:
Program received signal: “EXC_BAD_ACCESS”.
sharedlibrary apply-load-rules all
How can I track which object has already been release:
You can enable zombies, which will mark deallocated objects' memory
with what they used to be, and can also prevent anything from being
actually deallocated ever, but is a useful way to investigate this
kind of problem (if you can reach the problem before you run out of
memory :) )
See NSDebug.h in Foundation.framework for some info on this.
The code is rather simple:
NSArray *vPolyArray = [NSArray arrayWithObjects: ... ];
[vPolyArray release];
You're over-releasing vPolyArray. +arrayWithObjects: returns an
autoreleased instance, and you're also releasing it explicitly, so
by the time NSAutoreleasePool gets around to releasing it, it's
already gone.
_______________________________________________
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
Amin Negm-Awad
email@hidden
_______________________________________________
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