views:

29

answers:

1

My iphone app plays a slide show made up of 5 user images.  These images are stored using core data.  I was noticing that memory was building up every time a different slide show was played and it was not releasing any of the previously played slide shows.   These images are showing up in Object Allocations as CFData. So I tried releasing this data in the dealloc method

CFRelease(slideshow.image1);
CFRelease(slideshow.image2);
CFRelease(slideshow.image3);
CFRelease(slideshow.image4);
CFRelease(slideshow.image5);

This releases the previous slideshow great...BUT when I go back to view that same slideshow again, it crashes.   I am guessing that I need to alloc/init these images again, but I am not sure how?  Or maybe I should be managing this memory in a different way?

+2  A: 

It sounds like you're CFRelease-ing data that you shouldn't, and since you're mucking around with the NSManagedObject, you inevitably get a crash when Core Data goes "WTF?"

By "it was not releasing" are you seeing a memory leak, or simple memory usage growth? If the former, then we'll need more information, especially if Core Data is leaking, you might need to file a bug report (which is unlikely). If the latter, then there's much you can do, since Core Data is in charge of its own memory management.

It's possible you could use a NSAutoreleasePool to optimize but I can't say more on that.

Shaggy Frog
It was just memory usage growth. I have not been able to find any memory leaks but I have been getting crashes. However, the crashes only seem to take place after a good amount of use. So my thinking was that it was memory build up was causing the instability.The crashes were usually taking place while editing images. After repeated use of the camera and image picker.
Sam
Growing memory usage isn't necessarily indicative of a problem. If you run your app using Leaks and find nothing -- especially while testing on a device -- then you probably don't have any leaks.
Shaggy Frog
Is there a way to re-allocate these NSManagedObjects after I call CFRelease? I can't make much sense of the Apple docs on this.
Sam
I'm not sure how to answer that question. Why are you allocating NSManagedObjects? I use CoreData mostly in conjunction with NSFetchedResultsController to get existing data; I use NSManagedObjectContext to insert new entities and deleteObject to get rid of them. I'm never allocating NSManagedObjects explicitly myself. You need to start from the top -- figure exactly what (not how) you need, and then figure out how to do it.
Shaggy Frog