Ios – set a breakpoint in malloc_error_break to debug

debuggingiosmallocobjective c

For me here getting error :

[self.points addObject:@{@"latt": 
[NSNumber numberWithFloat:(latitudeString.floatValue)],@"long": [NSNumber numberWithFloat:(longitudeString.floatValue]}];

Like this: malloc: * error for object 0x7f8480743a00: pointer being freed was not allocated
*
set a breakpoint in malloc_error_break to debug

After adding malloc_error_break in Symbolic Breakpoint in Breakpoint Navigator getting same error

Best Answer

For memory errors of this sort, ASAN (address sanitizer) can often be a helpful tool. It instruments your code so that it can catch incorrect uses of malloc & free where they happen, rather than later when they blow up. And it records the history of allocation & free events for a given address, so for instance if you had a double free, it would show you both free points.

You turn this on by editing the Run Scheme in Xcode, going to the Diagnostics tab, and turning on Address Sanitizer. This will require a rebuild, and the instrumented binaries will run a little slower, but generally not so much slower that you can't get your program to the point of failure.