使用API我得到500張圖片,並以異步方式上傳。然後我想將所有這些圖片保存在CoreData中,但由於內存不足導致應用程序崩潰。上傳許多文件並保存在CoreData中
當上傳完成後我調用方法createFromBlock
+(id)createFromBlock:(MRBlock *)block{
ManagedBlock *item = [ManagedBlock MR_createInContext:DefaultContext];
item.id = @(block.id);
item.name = block.name;
item.slidesInBlock = @(block.slidesInBlock);
item.sizeBlock = block.sizeBlock;
item.desc = block.desc;
item.imagePath = block.imagePath;
item.image = [MRUtils transformedValue:block.image];
item.price = block.price;
int i = 0;
ManagedItem *new = nil;
for (MRItem *lol in block.items){
NSLog(@"%i", i);
new = [ManagedItem createFromItem:lol];
new.block = item;
[item addItemsObject:new];
new = nil;
i++;
}
[DefaultContext MR_saveWithOptions:MRSaveSynchronously completion:nil];
return item;
}
在的foreach block.items應用的崩潰。大約在150-160個職位之後。
如果我評論new = [ManagedItem createFromItem:lol];
- 應用程序不崩潰
+(id)createFromItem:(MRItem *)object{
ManagedItem *item = [ManagedItem MR_createInContext:DefaultContext];
item.id = @(object.id);
item.title = object.title;
item.detail = object.detail;
item.imagePath = object.imagePath;
item.image = [MRUtils transformedValue:object.image];
return item;
}
你是否在某種批次中這樣做?或者只是一次 - 500個在一個循環中? –
Grzegorz Krukowski,只需一次 - 500個在一個循環中 – user1771125