ios - iOS 中的核心数据内存占用量不断增长
<p><p>我正在尝试备份 Core Data SQLite 数据库。此代码成功处理正在运行的数据库并合并 WAL 文件。不幸的是,每次它运行时,我都会看到我的内存占用大约 3-5 MB。这会在程序运行一段时间后引起问题。有人可以帮我恢复内存吗?我认为将所有内容设置为 nil 会释放 RAM 中的所有对象,但似乎并非如此。</p>
<pre><code>-(void) backupDatabaseWithThisTimeStamp: (int) timeStamp withCompletionBlock:(void (^)(void))completion {
NSDate *backupDate = ;
NSError *error;
;
if (error) {
NSLog(@"error -> %@",error);
}
dispatch_async(self.backupQueue, ^{
// Let's use the existing PSC
NSPersistentStoreCoordinator *migrationPSC = [ initWithManagedObjectModel:];
// Open the store
id sourceStore = options:nil error:nil];
if (!sourceStore) {
NSLog(@" failed to add store");
migrationPSC = nil;
} else {
NSLog(@" Successfully added store to migrate");
NSError *error;
NSLog(@" About to migrate the store...");
id migrationSuccess = options: withType:NSSQLiteStoreType error:&error];
if (migrationSuccess) {
NSLog(@"store successfully backed up");
// Now reset the backup preference
NSManagedObjectContext *tempContext = [ initWithConcurrencyType:NSPrivateQueueConcurrencyType];
tempContext.persistentStoreCoordinator = migrationPSC;
tempContext.undoManager = nil;
// clip out data
;
migrationPSC = nil;
tempContext = nil;
}
else {
NSLog(@"Failed to backup store: %@, %@", error, error.userInfo);
migrationPSC = nil;
}
}
migrationPSC = nil;
dispatch_async(dispatch_get_main_queue(), ^{
if (completion) {
completion();
}
});
});
}
self.backupQueue = _backupQueue = dispatch_queue_create("backup.queue", DISPATCH_QUEUE_SERIAL);
localStoreOptions =
- (NSDictionary*)localStoreOptions {
return @{NSMigratePersistentStoresAutomaticallyOption:@YES,
NSInferMappingModelAutomaticallyOption:@YES,
NSSQLitePragmasOption:@{ @"journal_mode" : @"DELETE" }};
}
</code></pre>
<p>注释掉迁移成功点之后发生的所有事情不会影响内存占用。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我看到的所有问题都直接与 Xcode 方案有关。
产品->方案
选择运行选项
UNCHECK -> 队列调试(启用回溯记录)</p>
<p>完成此操作后,所有内存占用增长立即消失。</p></p>
<p style="font-size: 20px;">关于ios - iOS 中的核心数据内存占用量不断增长,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/30445717/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/30445717/
</a>
</p>
页:
[1]