27

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];
JAL
  • 41,701
  • 23
  • 172
  • 300
brush51
  • 5,691
  • 6
  • 39
  • 73
  • 2
    "can't allocate region" means that there is no memory space left! Might be time to start looking into memory management and releasing unused resources. – eric Dec 12 '11 at 16:14
  • 5
    iOS, 14.5GB of allocation? Am I missing something here? – buddhabrot Dec 12 '11 at 16:15
  • no kidding. What's the ram on an iPhone 4? is it 1GB? – Max MacLeod Dec 12 '11 at 16:20
  • Without the code to analyse it further, I'd take a stab in the dark and say that if you're allocating 14.5GB then the chances are you're running out of memory (iOS devices generally don't have that much memory). The error code=12 also suggests this. – Paul McCabe Dec 12 '11 at 16:24
  • @MaxMacLeod I believe it's 500MB. – Paul McCabe Dec 12 '11 at 16:25
  • Simulator has more memory capacity than the device but that still seems high lol. Is that the full error output? – eric Dec 12 '11 at 16:28

3 Answers3

10

Sounds strange, but I had the same behavior when main thread was overloaded.

Memory usage was optimal enough: instruments shows no leaks and live memory was about 2Mb, no memory warnings while running on a device, all massive allocation was done inside autorelease pools etc.

But there was very huge process of storing data to db (using Core Data) made on main thread. Just moving the storing code to background process like this

dispatch_async(dispatch_get_global_queue
  (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  BOOL result = NO;
  result = [[DataManager sharedInstance] storeGuestsToDB];
  dispatch_async(dispatch_get_main_queue(), ^{
  //finalization
  }
}

fixed my problem.

Tamara
  • 851
  • 11
  • 14
  • I'm not sure that I understand you correctly... You shouldn't put it to main.m, but of course you may try to use something the same in your application. Just place the activity you think to be overloaded instead of my call to a DataManager. – Tamara Mar 25 '13 at 14:02
  • Thanks for your answer. This was exactly my problem. I was downloading and storing a JSON file (~90mb).. With moving the transactions into another thread I got rid of the problem. – Prine Sep 18 '14 at 21:52
  • It's not working for me...and I checked, it's not a memory leak. I'm exporting a GIF using `CGImageDestinationAddImage` – ninjaneer Jan 29 '16 at 02:27
7

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.

Community
  • 1
  • 1
eric
  • 4,863
  • 11
  • 41
  • 55
0

I had this issue due to a recursive call in a view controller's viewWillLayoutSubviews. I was invalidating the layout of a collection view causing an endless cycle of repeatedly laying out views.

JAL
  • 41,701
  • 23
  • 172
  • 300