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

Re: monitoring retainCount


  • Subject: Re: monitoring retainCount
  • From: "b.bum" <email@hidden>
  • Date: Wed, 26 May 2004 18:44:01 -0700

On May 26, 2004, at 4:12 PM, Stefan Fisk wrote:
i think you all are missing the point, i want to monitor the retain count in code, so that i can know when the objects i've created get destroyed, without polling each pass through the runloop etc.. what you're suggesting are debugging aids, i want to be notified atleast every time retainCount changes, preferably only when it reaches 0, and it should work while deployed on "vanilla" installs of os x..

Override -dealloc and post a notification. -dealloc will only be invoked when the retain count has reached 0. Since you have the Notification center handy, do a [center removeObserver: self], too.

You can do the same for -retain, -release, and -autorelease.

Now, if you are talking about monitoring the destruction of all classes, things get a little more complex as their isn't a hook in ObjC to do that at the instance level (outside of contexts that are really only appropriate for debugging). There are lower level hooks found in /usr/include/objc/objc-runtime.h. I have used them in the past very effectively in the context of a debugging aid, but never for production code as it really isn't a good idea to override the allocators across the entire ObjC runtime within any given app.

All of the above is technically feasible, but I have never encountered a situation where relying upon retain/release/autorelease/dealloc generated notifications was the right way to architect the app. The closest is the pattern of removing observers, etc, in -dealloc. It is less of a global notification and more of a matter of cleaning up the object

This isn't meant to say that you haven't come across a situation where it *is* the right solution. If it is, I would like to better understand why because new things interest me (and there has been very little that is new in the retain/release/autorelease/dealloc front since it was introduced in 199{3,4,5} -- can't remember exactly when).

b.bum
_______________________________________________
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: 
 >Re: monitoring retainCount (From: "email@hidden" <email@hidden>)
 >Re: monitoring retainCount (From: Shawn Erickson <email@hidden>)
 >Re: monitoring retainCount (From: Stefan Fisk <email@hidden>)

  • Prev by Date: Forum notify
  • Next by Date: Re: monitoring retainCount
  • Previous by thread: Re: monitoring retainCount
  • Next by thread: Re: monitoring retainCount
  • Index(es):
    • Date
    • Thread