iphoneobjective-cmemory-managementmallocautorelease

How to find the cause of a malloc "double free" error?


I'm programming an application in Objective-C and I'm getting this error:

MyApp(2121,0xb0185000) malloc: *** error for object 0x1068310: double free
*** set a breakpoint in malloc_error_break to debug

It is happening when I release an NSAutoreleasePool and I can't figure out what object I'm releasing twice.

How do I set his breakpoint?

Is there a way to know what is this "object 0x1068310"?


Solution

  • You'll find out what the object is when you break in the debugger. Just look up the call stack and you will find where you free it. That will tell you which object it is.

    The easiest way to set the breakpoint is to:

    1. Go to Run -> Show -> Breakpoints (ALT-Command-B)
    2. Scroll to the bottom of the list and add the symbol malloc_error_break