Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - debugging "pointer being freed was not allocated" errors

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!

like image 622
adam Avatar asked Nov 17 '08 15:11

adam


2 Answers

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.

like image 52
Ish Avatar answered Nov 10 '22 17:11

Ish


I generally use NSZombie for such things, check this out

like image 25
wisequark Avatar answered Nov 10 '22 17:11

wisequark