• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSManagedObjectContext import issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSManagedObjectContext import issue


  • Subject: Re: NSManagedObjectContext import issue
  • From: Brett Powley <email@hidden>
  • Date: Wed, 8 Feb 2006 14:43:24 +1100

Hi Marcus,

I haven't run across this particular error, but I am doing something quite similar to you. My application imports around 7000 records from a text file on the first startup. When I did get it working, I was extremely impressed with the performance -- I had half expected this to put unreasonable demands on Core Data, but it seemed to handle it with aplomb.

Originally I was saving the managed object context after every insert, but this made it painfully slow. Saving at the end of all the imports seems to work fine (for me at least).

I don't do any flushing of the autorelease pool or anything; I did, however, have to be careful about allocating and releasing temporary objects myself rather than waiting for them to be autoreleased. I must admit that I haven't looked too closely at my memory management, but it seems to be fine. I have been assuming that the managed object context would handle memory management for the collection of objects. (If this *is* bad, I'd appreciate someone telling me what to do instead :-) )

The issues I did have were all involved in putting my import code in the right place, and in the right order. My import looks something like this (most of this is the autogenerated code you get anyway):


- (NSPersistentStoreCoordinator *) persistentStoreCoordinator {

    if (persistentStoreCoordinator != nil) {
        return persistentStoreCoordinator;
    }

    NSFileManager *fileManager;
    NSString *applicationSupportFolder = nil;
    NSURL *url;
    NSError *error;

fileManager = [NSFileManager defaultManager];
applicationSupportFolder = [self applicationSupportFolder];
if ( ![fileManager fileExistsAtPath:applicationSupportFolder isDirectory:NULL] ) {
[fileManager createDirectoryAtPath:applicationSupportFolder attributes:nil];
}


NSString *filePath = [applicationSupportFolder stringByAppendingPathComponent: @"BarnACLE.sqlite"];
url = [NSURL fileURLWithPath: filePath];
BOOL loadInitialData = ![fileManager fileExistsAtPath:filePath];

persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:nil error:&error]){
[[NSApplication sharedApplication] presentError:error];
}

if ( loadInitialData ) {
NSLog(@"File doesn't exist");
[self importStuff];

NSLog(@"Imported, saving");

[[self managedObjectContext] save:&error];


		NSLog(@"Imported, saved");

	}
	else
		NSLog(@"File already exists");


return persistentStoreCoordinator; }



then my import function parses the stuff from the text file and ultimately creates managed objects doing something like this:

NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *newThing = [NSEntityDescription insertNewObjectForEntityForName:@"Thing"
inManagedObjectContext:context];


and then calls setValue for the various attributes.


Cheers, Brett




On 08/02/2006, at 2:06 PM, Marcus S. Zarra wrote:

I am running into a very strange issue. I am attempting to import a large amount of data into a sqlite data store. In the application I spin off a separate thread and create the managed object context in the secondary thread. It uses its own persistent store and there are no other stores attached.

In this separate thread I have broken apart a csv file into an array of lines. I then loop through that array of lines and create managed objects -- 1-3 managed objects per line. Every x lines I have tried variations of the following:

flush the autorelease pool
save the context
reset the managed object context

If I only flush the pool, the memory gets out of control very quickly.

If I save the context, I eventually get an error:

AppKitJava: uncaught exception NSInternalInconsistencyException (+entityForName: could not locate an NSManagedObjectModel)
AppKitJava: exception = +entityForName: could not locate an NSManagedObjectModel
AppKitJava: terminating.


If I reset the context without saving, the data is thrown away.

If I do all three I get the error listed above.

My questions:

1. Has anyone run across this error before? Note that the context is not nil as I create it in this thread.
2. The application is written in Objective-C and while Java is used in another portion of the application it is not used in this thread or in this import.
3. According to Apple's Documentaiton reset on the context is supposed to reduce memory consumption but it does not seem to. What is the best way to keep memory under control while importing a large (5,000+) amount of data.


Thanks for any suggestions or ideas!

Marcus _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40process.com.au


This email sent to email@hidden

-------------------------------------------------------------- Brett Powley -- PhD Candidate Centre for Language Technology, Macquarie University, Australia p: +61-402-013050 f: +61-2-90120813 e: email@hidden w: http://www.ics.mq.edu.au/~bpowley faciendi plures libros nullus est finis frequensque meditatio carnis adflictio est --------------------------------------------------------------



_______________________________________________
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


References: 
 >NSManagedObjectContext import issue (From: "Marcus S. Zarra" <email@hidden>)

  • Prev by Date: NSManagedObjectContext import issue
  • Next by Date: Re: File permissions when copying files using NSFileManager
  • Previous by thread: NSManagedObjectContext import issue
  • Next by thread: Universal Binary Screensavers in 10.3?
  • Index(es):
    • Date
    • Thread