jeudi 25 février 2016

Static NSManagedObject will keep in Memory

I'm using CoreData to create a Static NSManagedObject and fetch from NSManagedObjectContext.

static YFYMRDepartment *rootOne;
if (!rootOne) {
    rootOne = [YFYMRDepartment MR_findFirstByAttribute:@"parent_id" withValue:@(0) inContext:[NSManagedObjectContext MR_defaultContext]];
}

return rootOne;

I'm using Magical Record, the MR_find code actually do some fetch job from context. However even after I deleted the sql file, the static object still there.

I delete the file like this:

NSError *error = nil;
NSURL *fileURL = pathForStore;
NSString *schemaURLString = [[fileURL absoluteString] stringByReplacingOccurrencesOfString:@".sqlite" withString:@".sqlite-shm"];
NSString *walURLString = [[fileURL absoluteString] stringByReplacingOccurrencesOfString:@".sqlite" withString:@".sqlite-wal"];
for (NSURL *romoveString in @[fileURL, [NSURL URLWithString:schemaURLString], [NSURL URLWithString:walURLString]]) {
    [[NSFileManager defaultManager] removeItemAtURL:romoveString error:&error];
    if(error) {
        // Hanldle error
    }
}

My question is why the object still there even I delete the store file.

Aucun commentaire:

Enregistrer un commentaire