Control memory overhead : how releasing custom NSMannagedObject ?
Control memory overhead : how releasing custom NSMannagedObject ?
- Subject: Control memory overhead : how releasing custom NSMannagedObject ?
- From: Jean-Luc Metzger <email@hidden>
- Date: Sun, 19 Aug 2007 10:35:23 +0200
Hello,
Sorry for my english, I am french and new user of coreData framework.
I need to managed a quiet big set of object in one context (nearly
2,000,000) of 3 different types. But I only need to keep 500 000
object in memory during all the job I have to do. This mean I don't
want use a [context reset] to free all the memory in use for one
NSManagedObjectContext. I keep them in a NSMutableDictionary to
retrieve it more rapidly than multiple fetch in context (I use a
NSSQLiteStoreType persitentStore).
So I try different things, but only one seems correct to me : use
[context refreshObject:anObjectIdontNeedAnymore mergeChange:NO]. But
anObjectIdontNeedAnymore is never released. To be sure I have extend
NSManagedObject to myManagedObject and override dealloc with an NSLog
that tails me my object is released. In fact I need more things in
myManagedObject but I'm not sure it's of interest here.
The code of myManagedObject is for entities objStats with an
attribute identification
@implementation myManagedObject
- (void) dealloc {
NSLog(@" release object %@", [self valueForKey:@"identication"]);
[super dealloc];
}
@end
The simplified code of the parser which show my problem (first I init
my parser and then call the parse method) :
@implementation parser
- (id) initWithContext:(NSManagedObjectContext *)moc {
id superInitReturn = [super init];
if(!superInitReturn || self != superInitReturn) return nil;
context = moc;
[context retain];
return self;
}
- (void) parse {
//listeObjectInMemory = [[NSMutableDictionary alloc]init]; //
Not use in this example
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager changeCurrentDirectoryPath:@"/xx/xxx/"];
NSDirectoryEnumerator *itEntrees = [fileManager
enumeratorAtPath:@"/xx/xxx/"];
NSString *entree=nil;
while(entree=[itEntrees nextObject]) {
[self parse:[NSString stringWithFormat:@"/xx/xxx/%@",entree]];
}
//[listeObjectInMemory release];
}
- (void) parseFile:(NSString *)filePpath {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
myManagedObject * anObjectIdontNeedAnymore;
NSString *file = [NSString stringWithContentsOfFile:path];
NSMutableArray *lignes = [NSMutableArray arrayWithArray:[file
componentsSeparatedByString:@"\n"]];
//the first ligne of the file gives the identification
NSString * identi = [lignes objectAtIndex:0];
anObjectIdontNeedAnymore = [NSEntityDescription
insertNewObjectForEntityForName: objStats
inManagedObjectContext:context];
[anObjectIdontNeedAnymore setValue: identi forKey:@"identication"];
NSError *error=nil;
///////>>>>>
if(![context save:&error]) {
NSLog(@"erreur %@",error);
}
[context refreshObject: anObjectIdontNeedAnymore mergeChanges:NO];
///////>>>>>
[pool release];
}
obj is never released. If I change part of code in ///////>>>>>
like this (just place the refresh before the save statement - I kwon
its a bit stupid) : the object is released before to be save !
[context refreshObject: anObjectIdontNeedAnymore mergeChanges:NO];
if(![context save:&error]) {
NSLog(@"erreur %@",error);
}
What should I change ? What I misunderstood that makes me crazy ?
Could you help me ?
Thanks in advance
Jean-Luc
_______________________________________________
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