Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interpret "failed to VM allocate" from Guard Malloc in Xcode

Is there a good tutorial on interpretation and problem-solving with Guard Malloc?

I'm getting message like "Failed to VM allocate 262144 bytes", and I have no idea what this means. Initially I thought it was the lack of RAM in the system, but maybe not so. If it is a problem I desperately need to learn how to interpret and catch the error.

Another question I have with Guard Malloc is whether it guards memory allocated in C codes of the project (it should right? considering the name) or only applying only to Objective-C? The reason I asked is that I just found out NSZombieEnabled only applies to Obj-C.

Help very much appreciated. I've been messing with likely memory errors for days. And I've not been able to compile Valgrind for iOS yet.

like image 602
huggie Avatar asked Jul 25 '12 00:07

huggie


1 Answers

1) I've been chalking up allocation failures with guard malloc on to address space exhaustion -- every allocation takes up at least a page of address space that can't be reused. Uses of memory that is not currently allocated will crash in guard malloc, not cause allocation failures.

2) as the name suggests, guard malloc replaces the implementation of malloc(3), so C code that uses malloc will be checked.

Note that guard malloc is not a silver bullet. You still have to expose your app's bugs through testing; guard malloc just causes crashes to happen earlier and more reliably.

You might also want to read "man libgmalloc".

like image 122
Scott Wolchok Avatar answered Sep 20 '22 06:09

Scott Wolchok