Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: release check



On Mar 14, 2007, at 2:26 PM, I. Savant wrote:

On Mar 14, 2007, at 5:19 PM, Ahmet Taha Sakar wrote:
Is there a way to check right before program terminate to see if I have
forgotten to release any variables. I am curious about this, so I can go
and figure out where they should be released and add release code.


That would be utterly unnecessary as *all* application resources are reclaimed by the system when the application terminates.

I believe Ahmet was asking about how to check an application for leaks as it was about to exit, not how to perform extra releases at exit.


Detecting leaks at exit is fairly easy on Mac OS X.

1. Set up an executable for your application that has the following malloc(3) environment variables set:

  MallocStackLogging=1
  MallocScribble=1
  MallocPreScribble=1

You can see what these environment variables do in the malloc(3) man page.

2. Set a breakpoint on _exit (underscore included), which is the underlying API invoked to exit a process. See the _exit(2) man page for details. Setting this breakpoint will let you catch your application at a point where it should be completely 100% done (with the possible exception of detached threads).

3. Run your application and do stuff, and then quit it. You should hit the breakpoint from #2.

4. While your application is stopped in the debugger, use the leaks(1) and heap(1) command-line tools to inspect your application's memory after it has run for leaked objects.

You can also use other performance tools such as ObjectAlloc.app and MallocDebug.app to track your application's memory behavior; see their documentation for details on their use.

  -- Chris

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >release check (From: "Ahmet Taha Sakar" <email@hidden>)
 >Re: release check (From: "I. Savant" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.