views:

6623

answers:

5

When over freeing a pointer you may see an error such as

"pointer being freed was not allocated"

When debugging with the simulator, I add a build argument MallocStackLogging = YES - this allows me to use malloc_history in the terminal to track down where I have over freed a pointer.

If I debug on the device with this build argument I get all sorts of console errors "cannot create stack log files" etc.

Oddly, I get some over freed pointer errors appearing on the device, but not on the simulator.

Has anyone had any experience tracking these down using the device itself?

Thanks!

+1  A: 

I generally use NSZombie for such things, check this out

wisequark
A: 

NSZombie is useful to prevent accidental release on object, but without MallocStackLogging, I don't know how to trace a particular instance object creation.

I have the same problem with Chris, I still can't find a way to turn on MallocStackLogging to debug on the device.

Any luck debugging with MallockStackLogging on the iPhone?
pix0r
A: 

You need to set the MallocStackLogging env variables on the target executable...

To access these settings, select your executable from the Groups & Files pane in XCode, then Get Info.

Go to the Arguments tab and add the following entries into the “Variables to be set in the environment” box:

Gabe
+2  A: 

Another way to do this. Make sure to turn NSZombie on so it reports the memory address of the object that is getting the extra release. Then Run with Performance Tool->Object Allocations. This will bring up instruments. Look at the Console log as provided by Xcode organizer. Once you get the crash lookup the memory address in instruments. You will see the entire history of mallocs/frees on that object, as well as links straight into your code.

Ish
A: 

Please can anybody tell me how to use this malloc_history what do you need to enable and where do you need to write malloc_history? in the dbg console or elsewhere? I am really confused. I have the same error and i can't find what is wrong just by looking at the address. Any other tips on how to track down this error are welcome. Thx.

kudor gyozo