Search code examples
iosmemory-managementmallocallocation

Malloc error "can't allocate region" failed with error code 12. Any idea how to resolve this?


i am getting this error and dont know what to do with that:

AppName(3786,0xa0810540) malloc: *** mmap(size=16777216) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

If i set a breakpoint to that line that occurs the error, i dont know what i have to search specially for. In instruments i have checked the allocations and the value is increasing until 14,5 GB of all allocations.

Can someone give me help?
brush51

EDIT 1:
More informations:
- I am trying this in the simulator, not on the iOS device.
- Thats all of the output(i am getting this error more times). - the error occurs on this line:

NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *fetchREntitySetsCards = [[[NSFetchRequest alloc] init] autorelease];
//NSFetchRequest *fetchREntityRelCardsAnswersNotes = [[[NSFetchRequest alloc] init] autorelease];

NSEntityDescription *entitySetsCards = [NSEntityDescription entityForName:@"EntitySetsCards" inManagedObjectContext:context];
//NSEntityDescription *entityRelCardsAnswersNotes = [NSEntityDescription entityForName:@"EntityRelCardsAnswersNotes" inManagedObjectContext:context];
setEntity:entityCard];
[fetchREntitySetsCards setEntity:entitySetsCards];
//[fetchREntityRelCardsAnswersNotes setEntity:entityRelCardsAnswersNotes];

NSArray *fetchedObjSetsCards    = [context executeFetchRequest:fetchREntitySetsCards error:&error];
//The error is here--->
//NSArray *fetchedObjRelCardsAnswersNotes   = [context executeFetchRequest:fetchREntityRelCardsAnswersNotes error:&error];


//Badges für TabBarItem Inbox setzen
setsCount = [context countForFetchRequest:fetchREntityUserSet error: &error];
cardsCount = [context countForFetchRequest:fetchREntityCard error: &error];

Solution

  • Googling will reveal quite a few tutorials on using instruments to understand what is going on with your memory:

    How to debug memory leaks: (tutorial)
    http://www.raywenderlich.com/2696/how-to-debug-memory-leaks-with-xcode-and-instruments-tutorial

    And another:
    Finding Obj-C memory leaks (video)
    http://www.youtube.com/watch?v=R449qEuexNs&feature=related

    *There are many similar questions on stackoverflow you might benefit from.