I am syncing around 5000 images from server in my iPad application.size of those images is around 2.5 GB and my iPad also have sufficient space.
But after syncing only 375 images my application start crashing with the following reason
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:
I am saving images in Document Directory using core data.
Please guide me if there is any restriction of saving data for application. And all this operation i am performing on main thread.
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];
}