我在我的 iPad 应用程序中从服务器同步了大约 5000 个图像。这些图像的大小约为 2.5 GB,我的 iPad 也有足够的空间。

但仅同步 375 张图像后,我的应用程序开始崩溃,原因如下

malloc: *** mmap(size=1048576) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
2013-02-14 06:20:50.058 AAA[1250:907] ***
Terminating app due to uncaught exception 'NSMallocException',
 reason: 'Attempt to allocate 1048576 bytes for NS/CFData failed'

*** First throw call stack:

我正在使用核心数据在文档目录中保存图像。

如果对保存应用程序数据有任何限制,请指导我。我在主线程上执行的所有这些操作。
 for (int i = 0; i < [shadowElement3 count]; i++)
        {
            NSMutableArray* array = [[NSMutableArray alloc] init];
            Product* failedBankInfo = [NSEntityDescription insertNewObjectForEntityForName:@"Product"                                                                    inManagedObjectContext:context];

            NSXMLElement* element11    = [shadowElement3 objectAtIndex:i];
            NSString* strPath = [element11 stringValueForNode:@"B1_COD"];

            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
            NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:strPath];

            NSLog(@"%@",[element11 stringValueForNode:@"img"]);
            NSData* receivedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:              [element11 stringValueForNode:@"img"]]];
            [receivedData writeToFile:savedImagePath atomically:YES];

            [array addObject:savedImagePath];

}

最佳答案

您可能需要使用 Autorelease pool 。根据该文档,“如果您编写一个创建许多临时对象的循环。”

关于iphone - 保存 250 mb 数据后 iPad 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14868019/

10-12 00:11
查看更多