I realize this question has been asked before but I didn't find any answers that actually resolved it, so...asking again.
I'm using ARC. My app takes photos from an AVCaptureSession at periodic intervals and saves them to core data. I get the NSData object by calling UIImagePNGRepresentation(). As this is happening, memory steadily climbs and the app eventually quits due to memory pressure...but there are no leaks. Instruments shows that for each photo, 500k is being malloced and it never gets released.
The answer I keep coming across is to wrap UIImagePNGRepresentation, or indeed the whole method body, in an autoreleasepool, but this did not help.
I am reasonably certain that the UIImagePNGRepresentation call is the culprit, because when I comment it out, no more memory problems (or images to save).
Would appreciate any help here...is there another way to grab NSData from a UIImage? Is this just another SDK bug we have to live with?
-(void)photoTimerFired:(NSTimer*)timer
{
...
ManagedDataPoint *lastPoint = [_currentSession.dataPoints lastObject];
_lastImage = [_imageCapturer singleImage];
Photo *newPhoto = [NSEntityDescription insertNewObjectForEntityForName:@"Photo"
inManagedObjectContext:self.managedObjectContext];
// Line below is the culprit.
newPhoto.photoData = UIImagePNGRepresentation(_lastImage);
newPhoto.managedDataPoint = lastPoint;
}
[NSManagedContext -refreshObject:newPhoto mergeChanges:NO]
to turn your object back into a fault after you've saved? Are you sure it's not that the Core Data objects are keeping the data alive? – Tommy