• 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: How do I debug an autorelease crash?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I debug an autorelease crash?


  • Subject: Re: How do I debug an autorelease crash?
  • From: Jerry Seeger <email@hidden>
  • Date: Sat, 13 Sep 2003 09:38:10 -0700

Your theory about manually releasing and autoreleased object is almost certainly correct. Since it is very difficult to find out what the intended target of the objc_msgSend was intended to be, you may have to resort to a more painstaking approach.

One thing I have done, and if there are better methods I would love to hear about them, is to log each release and retain. You could also have the log entry include the retainCount of each object in your data model.

Or here is something I just thought of that you could try - implement release in your subclass, and if the retain count of the object is one, look in the autorelease pool before calling [super release]. If it is in the autorelease pool, raise an exception. You would probably want to turn this off in a shipping project for performance reasons.

That technique will only work with your classes, not the cocoa library classes - unless you want to start using categories, which may be risky. Theoretically, you could put a category on NSObject that would do the check for every object in your app, but you would have to reproduce the default release code. I suppose you could look in GNUStep for a start. Probably not worth it, but it would be educational.

Maybe it would be easier to subclass or add a category to the autorelease pool.

The other thing to do is sift through your code, checking every place where the word "release" occurs, and making sure it is balanced by an alloc or a retain. Chances are you are using a constructor for an object and assuming that it is retained when in fact it has been put in the autorelease pool. Methods like NSString's stringWithFormat: put the result in the autorelease pool.

The autorelease pool is emptied at the end of each event loop, so chances are that whatever you are releasing incorrectly was created as a result of the most recent event.

Sorry if this is rambling; AFIK there is no silver bullet to solve this type of problem. I look forward to hearing if others have tried any of above techniques or have come up with better ones.

Jerry


On Saturday, September 13, 2003, at 08:07 AM, Dave Riggle wrote:

I got all my code wired together yesterday, which means my problem could be anywhere. Is there an easy way to track down the culprit? I crash with a signal 11 here:

0 objc_msgSend
1 NSPopAutoreleasePool
2 -[NSApplication run]
3 NSApplicationMain
4 main

What exactly causes this crash anyway? Have I manually released an autoreleased object? It seems like it would be more useful to get a signal raised at the time of the error rather than at the end of the run loop.

Dave
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >How do I debug an autorelease crash? (From: Dave Riggle <email@hidden>)

  • Prev by Date: Re: Another autorelease question
  • Next by Date: Re: Another autorelease question
  • Previous by thread: Re: How do I debug an autorelease crash?
  • Next by thread: Re: How do I debug an autorelease crash?
  • Index(es):
    • Date
    • Thread