Skip to content

Instantly share code, notes, and snippets.

@sgoodwin
Created October 12, 2012 16:50
Show Gist options
  • Save sgoodwin/3880208 to your computer and use it in GitHub Desktop.
Save sgoodwin/3880208 to your computer and use it in GitHub Desktop.
Saving data downloaded off the inter webs
NSString *dataPath = [weakOperation tmpFilePath];
NSManagedObjectContext *context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[context setParentContext:mainContext];
[context performBlock:^{
NSError *findingError = nil;
GOFeedItem *thisItem = (GOFeedItem *)[context existingObjectWithID:objectID error:&findingError];
if(!thisItem){
NSLog(@"Error finding item %@: %@", [feedItem title], [findingError userInfo]);
}
[thisItem setAudioData:[NSData dataWithContentsOfFile:dataPath]];
NSError *savingError = nil;
BOOL saved = [context save:&savingError];
if(!saved){
NSAssert(NO, @"FUCK!");
}
[context reset];
}];
@sgoodwin
Copy link
Author

According to Instruments, the child context is gone, but there's still a Malloc the size of that file there still alive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment