Malloc错误"无法分配区域"失败,错误代码为12.任何想法如何解决?

bru*_*h51 21 malloc memory-management allocation ios

我收到此错误,不知道该怎么办:

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
Run Code Online (Sandbox Code Playgroud)

如果我设置断点到发生错误的那一行,我不知道我要专门搜索什么.在仪器中,我检查了分配,并且值增加到所有分配的14,5 GB.

有人可以帮我吗?
brush51

编辑1:
更多信息:
- 我在模拟器中尝试这个,而不是在iOS设备上.
- 这就是所有的输出(我得到这个错误的次数更多). - 此行发生错误:

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];
Run Code Online (Sandbox Code Playgroud)

Tam*_*ara 10

听起来很奇怪,但是当主线程被重载时我有同样的行为.

内存使用情况足够最佳:仪器显示没有泄漏,实时内存大约为2Mb,在设备上运行时没有内存警告,所有大量分配都是在自动释放池内完成的.

但是存在将数据存储到主线程上的db(使用Core Data)的非常庞大的过程.只需将存储代码移动到这样的后台进程即可

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
  }
}
Run Code Online (Sandbox Code Playgroud)

解决了我的问题.


eri*_*ric 6

谷歌搜索将揭示相当多的使用乐器的教程来了解你的记忆发生了什么:

如何调试内存泄漏:(教程)
http://www.raywenderlich.com/2696/how-to-debug-memory-leaks-with-xcode-and-instruments-tutorial

另一个:
发现Obj-C内存泄漏(视频)
http://www.youtube.com/watch?v=R449qEuexNs&feature=related

*有关stackoverflow的许多类似问题,您可能会从中受益.