0
votes

Dear community. Bellow is a part of code, which working, but product for me two problems (code working in AppDelegate main thread and start from select objects and press button: 1. Sometimes, and i don't understand where in code i seen error. I can't understand, where mistake (u can see it bellow) is start, but this happened particularly if i have data inside (SQLLite file is around 70Mb). 2. When delete process is working, application start eat memory from 40Mb to 512Mb and stay on same level after process is done. Memory GC is enabled.

Can u suggest something to optimize it? I has crazy two weeks, where i check around google and other resources and try to combine code inside my application.

p.s. some notes - if i don't save moc, i can't working, bcs immediately after data deleted i start synchronization and fill same data. If i don't do a save, i has double volumes for each entity.

2011-01-21 12:54:11.158 snow[14721:9da7] Failed to process pending changes before save. The context is still dirty after 100 attempts. Typically this recursive dirtying is caused by a bad validation method, -willSave, or notification handler. 2011-01-21 12:54:11.160 snow[14721:9da7] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to process pending changes before save. The context is still dirty after 100 attempts. Typically this recursive dirtying is caused by a bad validation method, -willSave, or notification handler.' * Call stack at first throw: ( 0 CoreFoundation 0x00007fff885317b4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x00007fff88bc10f3 objc_exception_throw + 45 2 CoreData 0x00007fff8005a654 -[NSManagedObjectContext(_NSInternalChangeProcessing) _prepareForPushChanges:] + 244 3 CoreData 0x00007fff8005a0af -[NSManagedObjectContext save:] + 207 4 snow 0x0000000100006fe9 __30-[AppDelegate syncOneCarrier:]_block_invoke_0 + 1657 5 Foundation 0x00007fff87c4e682 -[NSBlockOperation main] + 157 6 Foundation 0x00007fff87c3ede4 -[__NSOperationInternal start] + 681 7 Foundation 0x00007fff87d1dbeb __doStart2 + 97 8 libSystem.B.dylib 0x00007fff85f082c4 _dispatch_call_block_and_release + 15 9 libSystem.B.dylib 0x00007fff85ee6831 _dispatch_worker_thread2 + 239 10 libSystem.B.dylib 0x00007fff85ee6168 _pthread_wqthread + 353 11 libSystem.B.dylib 0x00007fff85ee6005 start_wqthread + 13

    NSUInteger x = 0;
    NSError *error = nil;

    for (NSManagedObject *carrier in [carriersArrayVisible selectedObjects]) 
    {
        NSString *carrierName = [NSString stringWithString:[carrier valueForKey:@"name"]];
        [carriersToExecute addObject:carrierName];
        [managedObjectContext deleteObject:carrier];
        //[managedObjectContext processPendingChanges];
        if (x % 10 == 0) {
            //[managedObjectContext save:&error];
            [managedObjectContext processPendingChanges];

            if (error) NSLog(@"Failed to save to data store syncOneCarrier: %@", [error localizedDescription]);
            [pool drain],pool = nil;
            pool = [[NSAutoreleasePool alloc] init];
        }
        x++;
    }
    [pool drain],pool = nil;

    [managedObjectContext save:&error];
1

1 Answers

0
votes

Based on the error you are doing something bad in a validation method somewhere.

  • Do you have subclasses for your managed objects?
  • Do those subclasses have validation methods in them?
  • Do those validation methods touch other managed objects or delete objects or something else that should not be done in a validation method?

Check there first, post any validation code you have and then perhaps someone can help you solve this issue.