in my SQLite backed Core Data app, a search action fetches from a
large number of objects (>1.000.000) only to show them in a table.
When the user exits search mode (search string empty), I'd like to
free the managed objects to restore the app's normal memory footprint.
I do that by resetting the managed context, but it doesn't seem to
work, physical memory stays where it was when the fetch was completed.
Strangely, in ObjectAlloc instrument I can see the fetched objects
being deallocated, but the physical memory still peaks.

If ObjectAlloc shows the fetched objects being deallocated, but top shows a large RSIZE, and the heap command shows a very large heap thats most unused, then you're doing everything you can on the deallocation side. There is a difference between heap size, and VM allocated address space. This issue is caught at the boundary, where the malloc system won't aggressively deallocate address space after the memory using it has been deallocated. It doesn't, because as a general rule that's a net loss. So your only choice is to either (a) not worry about it or (b) reduce peak memory. (b) reducing the heap high watermark is a separate problem than simply freeing all the memory you allocate. Reducing peak memory will have many other performance benefits besides making your RSIZE look pretty.

If you're using an NSArrayController in Entity mode, you can turn on Use Lazy Fetching. You'll want to disable auto-rearrange content. This works on 10.5. On 10.6 and iPhoneOS, you have more options, including using Batched Fetching on the fetch request with - setFetchBatchSize. This will make a vast reduction in peak memory when working with such a large result set. Working with 1 million objects like this will take ~16MB of RAM.

- Ben

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to