Re: Coredata performance problem : massive insertion produces error in allocate region
Re: Coredata performance problem : massive insertion produces error in allocate region
- Subject: Re: Coredata performance problem : massive insertion produces error in allocate region
- From: Julio Cesar Silva dos Santos <email@hidden>
- Date: Sun, 11 Mar 2007 09:45:54 -0300
Put all your code inside an NSAutoreleasePool:
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
.
.
.
[pool release];
and delete the line [obj release]. But 'insert a large amount of
instances in small time' may be difficult to figure out if we don't
know what you mean by small time. You can take a look at NSThread. It
will prevent UI locking.
Julio Cesar Silva dos Santos
email@hidden
Skype: jcssantos01
Blogjective-C
http://www.jcs.santos.nom.br/wp
FetchYourLyrics
http://www.jcs.santos.nom.br/fyl/fyl.html
On 11/03/2007, at 06:46, Kubernan At 10191 Tec. wrote:
Hello,
I'm new in coredata and i have a big performance problem.
My application inserts in one step about 60 000 instances of an
entity (calling 60 000 times this method):
-(void)insertALine:(NSString *)line
{
countOfInsertedLines++;
NSArray *anArray = [line componentsSeparatedByString:@" "];
NSEntityDescription *entity;
entity = [[[[NSApp delegate] managedObjectModel] entitiesByName]
objectForKey: @"Entity"];
NSManagedObject *obj;
obj = [[NSClassFromString([entity managedObjectClassName]) alloc]
initWithEntity:entity insertIntoManagedObjectContext:[[NSApp
delegate] managedObjectContext]];
[obj setValue:[anArray objectAtIndex:0] forKey:@"val1"];
[obj setValue:[NSNumber numberWithInt:[[anArray objectAtIndex:1]
intValue]] forKey:@"val2"];
[obj setValue:[NSNumber numberWithInt:[[anArray objectAtIndex:2]
intValue]] forKey:@"val3"];
[obj setValue:selectedObject forKey:@"relationship"]; //
selectedObject<-->>Entity relationship
if (countOfInsertedLines > SYNC_CONTEXT_AFTER_MAX_LINE_INSERTED)
{
countOfInsertedLines = 0;
NSError *error;
[[[NSApp delegate] managedObjectContext] save:&error];
}
[obj release];
}
After several minutes, this code produces this error :
malloc: *** vm_allocate(size=81920) failed (error code=3)
malloc: *** error: can't allocate region
malloc: *** set a breakpoint in szone_error to debug
What i'm doing wrong ? What is the best strategy if i want to
insert large amount of instances in small time ? (the persistent
store coordinator uses NSSQLiteStoreType)
Thanks for your help.
K.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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