Re: Running out of memory with Core Data
Re: Running out of memory with Core Data
- Subject: Re: Running out of memory with Core Data
- From: Nicko van Someren <email@hidden>
- Date: Mon, 25 Jul 2005 13:35:00 +0100
On 25 Jul 2005, at 13:20, Ian G. Gillespie wrote:
I am writing a financial application that can import account and
transaction data from a previous version. When I try to import
data that contains about 10 accounts and some of these accounts
contain 1000s of transactions, my app reaches the 2 GB memory limit
and crashes. The import also takes a LONG time (on the order of
minutes).
My first thought was that it might be a memory leak, but running a
few tests with the command line tool "leaks" indicated that that
doesn't seem to be the case. My second thought was perhaps it was
related to the undo manager, so I tried clearing the undo stack
after each new transaction entity was created but that didn't help
either.
Can anyone suggest why my app might hitting the 2 GB limit? Has
anyone else successfully gotten Core Data to create 1000s of
entities with reasonable performance?
Are you trying to import all of this data in one pass? One thing you
might be running into is that your autorelease pool is filling up,
since in general unless you take other action the autorelease pool
only gets flushed once per cycle of the run loop. Try creating an
autorelease pool before you start the import of each transaction and
releasing it just after the transaction has been imported. For example:
for (a=0; a < numberOfAccounts; a++) {
transCount = ... // find out haw many transactions there are for
account 'a'
for(i=0; i<transCount; i++) {
NSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init];
// Import transaction 'i' from account 'a'
[arp release];
}
}
In general if you end up processing large sets of data within a
single function in Objective-C it's a good idea to regularly flush
the autorelease pool since otherwise the memory fills up with lots of
unreleased data and you can find yourself running out of room even
though the memory doesn't contain anything of importance any more.
Cheers,
Nicko
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden