• 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: Debugging retainCount
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Debugging retainCount


  • Subject: Re: Debugging retainCount
  • From: Brent Gulanowski <email@hidden>
  • Date: Tue, 15 Jul 2003 10:39:02 -0400

On Monday, July 14, 2003, at 10:56 PM, The Amazing Llama wrote:

I had a memory leak in my program where I was autoreleasing too often (which is the memory leak I always seem to have), and I think I've figured out a simple way to track these things down.

Why couldn't NSObject be enhanced so that every time it gets an -autorelease message, it increments a counter. It then checks this counter against it's retainCount and debugger-breaks if the pending autoreleases are greater than the retains.

I could do this myself with a poseAs: but I don't know how to decrement the counter on getting a release from the autorelease pool. I suppose you could check the stack, but that seems a little hackish.

However, this would make a very nice, very simple addition to the frameworks, but making the NSAutoreleasePool decrement the counter before calling -release.

Unless (as I probably am) I am overlooking something simple that makes all this impossible. Would this work?


My solution for balancing retains and releases has always been pretty low-tech. I use the PB search facilities to look for every instance of alloc, retain and release (using "contains" so it gets autorelease, too), and make sure the required balance is satisfied. It means I also make sure that every class instantiates and frees its own objects, except for legitimate exceptions to that rule (like NSData +dataWithBytesNoCopy:freeWhenDone:). I find this much more reliable than anything else I've tried.


--
Brent Gulanowski email@hidden
_______________________________________________
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: 
 >Debugging retainCount (From: The Amazing Llama <email@hidden>)

  • Prev by Date: Re: iTunes playlist icons?
  • Next by Date: Re: NSDocument Default Contents
  • Previous by thread: Re: Debugging retainCount
  • Next by thread: Re: Debugging retainCount
  • Index(es):
    • Date
    • Thread