We're running into a situation where Core Data is making very large
memory allocations when faulting in small amounts of data.

The entity has:
  - 2x Date
  - Int16
  - 4x Int32
  - Boolean
  - String
  - to-one relationship
  - String (in a subentity)
  - to-one relationship (in a subentity)
  - to-many relationship (in another subentity)

Those should be ~128 bytes on 32 bit.

But when these are faulted in, according to Instruments, Core Data
allocates a GeneralBlock-528384 per record!  Even if you naively
preallocated a good chunk of memory for the strings, I can't imagine
using more than 1-2KB per record, so  516KB is totally ridiculous.

The stack trace is:
   5 <our code>
   4 CoreData -[_NSFaultingMutableSet objectEnumerator]
   3 CoreData -[_NSFaultingMutableSet willRead]
   2 CoreData -[NSManagedObjectContext(_NSInternalAdditions)
_retainedObjectWithID:optionalHandler:withInlineStorage:]
   1 CoreData +
[NSManagedObject(_PFDynamicAccessorsAndPropertySupport)
allocWithEntity:]
   0 CoreData _PFAllocateObject

This is allocating an object across a to-many relationship. A 516KB allocation for a single managed object is wrong. It would require your entity have over 100,000 properties, and the limit is 2^15 properties per entity.

It could be a bug in Core Data, or a memory smasher in your app that corrupts either our data structures or the ObjC runtime structures. Or the stack trace here could be computed incorrectly. If the stack trace were off slightly, then a hypothetically reasonable allocation would be for the CFSet holding the contents of the to-many relationship, assuming it had 50-100 thousand entries.

malloc_history and libgmalloc (see man page) may help produce some more information.

If you can reproduce this in a sample project with your model, you should definitely file a bug. If you can attach your program and steps to reproduce, you could file a bug with that as well.

- 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