我在我的 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];
}