On Mar 18, 2011, at 15:25, Nick Zitzmann wrote:

>  I have an application that loads tens of thousands of CoreData managed 
> objects across several threads, where each thread has its own unique managed 
> object context.
> 
> When I run the allocations instrument in Instruments, I can see that an eight 
> digit amount of bytes is being gobbled up & not freed by thousands of 320 
> byte mallocs, each of which has the following stack trace:
> 
>   0 CoreData _PFAllocateObjects
>   1 CoreData +[NSSQLRow 
> newBatchRowAllocation:count:forSQLEntity:withOwnedObjectIDs:andTimestamp:]
>   2 CoreData -[NSSQLCore 
> _prepareResultsFromResultSet:usingFetchPlan:withMatchingRows:]
>   3 CoreData -[NSSQLCore _newRowsForFetchPlan:selectedBy:withArgument:]
>   4 CoreData -[NSSQLCore newRowsForFetchPlan:]
>   5 CoreData -[NSSQLCore 
> _prefetchRelationshipKey:sourceEntityDescription:sourceObjectIDs:prefetchRelationshipKeys:inContext:]
>   6 CoreData -[NSSQLCore _prefetchWithFetchRequest:withObjectIDs:inContext:]
>   7 CoreData -[NSSQLCore _newRowsForFetchPlan:selectedBy:withArgument:]
>   8 CoreData -[NSSQLCore newRowsForFetchPlan:]
>   9 CoreData -[NSSQLCore objectsForFetchRequest:inContext:]
>  10 CoreData -[NSSQLCore executeRequest:withContext:]
>  11 CoreData -[NSPersistentStoreCoordinator(_NSInternalMethods) 
> executeRequest:withContext:]
>  12 CoreData -[NSManagedObjectContext executeFetchRequest:error:]
> 
> Question: What does my program have to do to release all of that memory? I've 
> already tried resetting and releasing the managed object contexts, and 
> Instruments confirms that they're gone, but that doesn't clean up this memory.

NSSQLRow is apparently part of Core Data's internal store cache, which is 
mentioned somewhere in the documentation. I suspect it doesn't contain any Core 
Data managed objects, but rather raw property data fetched from SQL. There's no 
API for managing it, and the only way I ever found of clearing it at all was to 
reset (or perhaps it was destroy, can't quite remember now) the managed object 
context. I spent, literally, weeks trying other approaches, all useless.

It's possible that you didn't close *all* of the contexts, and that's keeping 
the cache contents alive. IIRC I wasn't dealing with multiple contexts.

It's also possible that closing the contexts works lazily -- the cache contents 
aren't really dumped until other data needs to be loaded into it. That would 
mar your view of things in Instruments, if you weren't expecting it.

Also, in my case, I had a small number of very large objects.


_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to