adam
adam

Reputation: 22587

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!

Upvotes: 7

Views: 26903

Answers (4)

Eshwar Chaitanya
Eshwar Chaitanya

Reputation: 942

Please test the program for memory leaks,Also check autoreleases and whether you are releasing objects properly or not.Also we need to check whether a released object has a memory allocated or not.You also need to be careful regarding autorelease,because accidentally we might release an array or a string or any object that is already autoreleased...hope it helps and works!

Tip: You can test for leaks by analyzing your project(click shift+command+k)

Upvotes: 0

Ish
Ish

Reputation: 1905

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.

Upvotes: 9

Gabriel
Gabriel

Reputation: 963

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:

Upvotes: 0

wisequark
wisequark

Reputation: 3268

I generally use NSZombie for such things, check this out

Upvotes: 1

Related Questions