Ios4 malloc:mmap(大小=XX)失败(错误代码=12)

Ios4 malloc:mmap(大小=XX)失败(错误代码=12),ios4,memory-leaks,nsbundle,Ios4,Memory Leaks,Nsbundle,我的iPhone应用程序内存有问题,这让我很难受。 以下是我收到的错误消息: malloc:*mmap(大小=9281536)失败(错误代码=12) *错误:无法分配区域 我正在为这个应用程序使用ARC,以防这可能是有用的信息。 下面的代码只是使用捆绑包中的一个文件来加载核心数据实体 奇怪的是,只有在超过90次循环后才会发生崩溃; 虽然看起来mee的“内容”越来越小,但内存请求也应该越来越小 这是代码,如果有人可以看到一个缺陷,请让我知道 NSString *path,*contents,*li

我的iPhone应用程序内存有问题,这让我很难受。 以下是我收到的错误消息:

malloc:*mmap(大小=9281536)失败(错误代码=12) *错误:无法分配区域

我正在为这个应用程序使用ARC,以防这可能是有用的信息。 下面的代码只是使用捆绑包中的一个文件来加载核心数据实体

奇怪的是,只有在超过90次循环后才会发生崩溃; 虽然看起来mee的“内容”越来越小,但内存请求也应该越来越小

这是代码,如果有人可以看到一个缺陷,请让我知道

NSString *path,*contents,*lineBuffer;
path=[[NSBundle mainBundle] pathForResource:@"myFileName" ofType:@"txt"];
contents=[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

int counter=0;

while (counter<10000) {
    lineBuffer=[contents substringToIndex:[contents rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet]].location];
    contents=[contents substringFromIndex:[lineBuffer length]+1];
    newItem=[NSEntityDescription insertNewObjectForEntityForName:@"myEntityName"
                                                      inManagedObjectContext:context];
    [newItem setValue:lineBuffer forKey:@"name"];

    request=[[NSFetchRequest alloc] init];
    [request setEntity: [NSEntityDescription entityForName:@"myEntityName"
                         inManagedObjectContext:context]];
    error=nil;
    [context save:&error];

    counter++;
}
NSString*路径,*内容,*行缓冲区;
path=[[NSBundle mainBundle]pathForResource:@“我的文件名”,类型:@“txt”];
contents=[NSString stringWithContentsOfFile:路径编码:NSUTF8StringEncoding错误:nil];
int计数器=0;

而(counter我最终解决了使用NSMutableString而不是NSString作为内容的问题。 然后使用:[contents deleteCharactersRange:range]; 当然要充分保持射程。 在循环内部