Re: CoreData huge memory usage - is this right ?
Re: CoreData huge memory usage - is this right ?
- Subject: Re: CoreData huge memory usage - is this right ?
- From: Frank Reiff <email@hidden>
- Date: Tue, 18 Dec 2007 12:37:28 +0100
Hi,
I posted similar problems here a few weeks back, but nothing really
helped (at least on Leopard) until I simply reset the context.
My "tight" loop now ends with a
[context save: &error];
[context reset];
[pool release];
every few thousand inserts. This isn't great because it invalidates
all references for the context, so you need to keep track of the
object ids if you need to get an object back into the context after
the reset, but my memory usage is now down to nothing.
I'm not a great expert on CoreData but I suspect that the Leopard
implementation in non-garbage collected mode doesn't release newly
created managed objects properly until you reset the context. I tried
to disable the undo manager as suggested earlier in this thread but
that made no difference.. I didn't file a bug with Apple because I
just don't know enough about CoreData to be definite about it, but my
workaround works just fine.
I hope this helps.
Best regards,
Frank
On 14 Dec 2007, at 15:38, Martin Linklater wrote:
Hi - I'm in the process of writing code which will create and
populate a CoreData SQLite store. I have a few million objects to
deal with. I have written code which imports a text description of
my data and then iterates through inserting and setting attributes
of my CoreData objects. Things are going fine with the exception of
one problem I am having... I am seeing CoreData take huge amounts of
RAM to do it's thing. When my SQLite store is at around 10MB in
size, my task is taking upwards of 500+MB of memory.
I have run my application through 'Instruments' and the major
culprit for all this memory usage is CoreData - namely the
'GeneralBlock-x' where x is a number. I am trying to track down this
memory leak but I'm stuck as to where it is coming from. My code
follows the standard template XCode code for a CoreData Application,
and I am simply iterating through my object like this:
while( not end of file )
{
id coreDataElement = [NSEntityDescription
insertNewObjectForEntityForName:name in ManagedObjectContext:moc];
// add my attributes for the element
[coreDataElement setValue:value forKey:key];
[coreDataElement setValue:value forKey:key];
[coreDataElement setValue:value forKey:key];
etc.
[coreDataElement release];
// then every 1000 entries or so I am saving the context
[moc save:&error];
}
This code is executing fine, and my elements are indeed being
inserted into the CoreData store because I have ran this code with
an XML store and things are being stored fine. Saving of the moc is
returning with no errors too.
So I am stumped as to why CoreData is allocating an awful lot of
memory for this task... can anyone shed some light on what I'm doing
wrong ?
Apologies if this is a trivial error - I am very new to CoreData.
Thank you.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden