• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Autorelease pool
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Autorelease pool


  • Subject: Re: Autorelease pool
  • From: Michael Süssner <email@hidden>
  • Date: Thu, 8 Oct 2009 16:36:07 +0200

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

...

[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


  • Follow-Ups:
    • Re: Autorelease pool
      • From: Negm-Awad Amin <email@hidden>
References: 
 >Autorelease pool (From: Michael Süssner <email@hidden>)
 >Re: Autorelease pool (From: Wim Lewis <email@hidden>)

  • Prev by Date: How to ease the burden on the Garbage Collector?
  • Next by Date: Re: Autorelease pool
  • Previous by thread: Re: Autorelease pool
  • Next by thread: Re: Autorelease pool
  • Index(es):
    • Date
    • Thread