• 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: Instruments, how to fix leak in C Lib
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Instruments, how to fix leak in C Lib


  • Subject: Re: Instruments, how to fix leak in C Lib
  • From: Jens Alfke <email@hidden>
  • Date: Wed, 02 May 2012 12:05:11 -0700

On May 2, 2012, at 11:38 AM, David Hoerl wrote:

> Valgrind monitors every malloc, and when the app/program quits tells you not only what leaks you have, but the stack trace that got you to the allocation. Absolutely amazing. I've used it with several open source libraries I support.

Valgrind is cool, but the ‘leaks’ tool that’s always shipped with OS X can do what you describe above. You just have to set the environment variable MallocStackLogging when running your app/tool so ‘leaks’ can grab the backtraces:

	env MallocStackLogging=1 ./MyTool &
	leaks MyTool

One could argue that Instruments makes the ‘leaks’ tool obsolete, but I find it’s so quick and easy to use that I still turn to it. Especially since you can use it on an already-running app (although you lose the backtraces if the app wasn’t launched specially as above.)

Valgrind can do a lot more, including detecting illegal memory accesses — if you read or write even one byte past the end of a malloc block, it’ll tell you, and show you the stack trace and the position/size of the block. This has been really helpful in debugging some low-level bit-twiddly code I’m currently working on!

—Jens
_______________________________________________

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


References: 
 >Re: Instruments, how to fix leak in C Lib (From: David Hoerl <email@hidden>)

  • Prev by Date: Re: Instruments, how to fix leak in C Lib
  • Next by Date: Re: Minimal document-based app
  • Previous by thread: Re: Instruments, how to fix leak in C Lib
  • Next by thread: Re: Converting CGPathAddArcToPoint (or NSBezierPath equivalent) to a fixed number of CGPathAddCurveToPoint calls
  • Index(es):
    • Date
    • Thread