我正在使用coredata(第一次使用)保存大量的數據(圖像,視頻路徑,html文本) 當我使用prdicate提取數據fetchRequest NSArray內存使用增加10到15MB每次。有時它會跨越400-500mb..app減慢速度,但不會崩潰coredata數據提取增加內存使用ios
我想知道,它通常在覈心數據庫中嗎? 是否有任何方法來獲取數據而不增加內存使用量?
如果不是那麼我該如何解決這個問題。 如果有人知道原因或任何想法請分享。
我的代碼如下所示
-(void)GetDatafromPrimaryKey:(NSString *)PrimaryKeyTxt EntityName:(NSString *)EntityName {
NSError *error = nil;
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:EntityName inManagedObjectContext: context];
[fetch setEntity:entityDescription];
[fetch setPredicate:[NSPredicate predicateWithFormat:@"primaryKey == %@",PrimaryKeyTxt]];
// [fetch setIncludesPropertyValues:NO];
[fetch setShouldRefreshRefetchedObjects:NO];
chatAry = [context executeFetchRequest:fetch error:&error];
NSLog(@"---> %lu",(unsigned long)chatAry.count);
if (error != nil) {
// Deal with failure
}
else {
}
}
您應該將圖像和視頻保存在應用程序目錄中而不是核心數據中,並將該圖像視頻的路徑URL保存在覈心數據中......其他方式將大量圖像和視頻保存在覈心數據中會消耗更多內存,內存中的圖像和視頻一次將其保存到核心數據 –
@Sharma sir,我之前使用過DocumentsDirectory ..但結果相同。內存增加:( –
使用'sqlite'是推薦的方式來處理應用程序內的大量數據,它也是最喜歡的方式。 – vaibhav