Q: How can I avoid running out of memory when creating/deleting a lot of new core data items? 
Possible Duplicate:
How do i avoid running out of memory when performing a task on every item of core data? 

I posted this, which has a similar title, but is a different matter. I posted this separately to avoid confusion in asking 2 questions in the same question.
What I wish to do is add a lot of data to a core data store without running out of memory. Here is the code I currently have:
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Entry"];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(version == %@)", @"1.0"];

[request setPredicate:predicate];

NSArray *results = [[AppDelegate applicationDelegate].managedObjectContext executeFetchRequest:request error:nil];

int i = 0;

while (i < results.count) {

    Entry *entry = [results objectAtIndex:i];

    entry.version = @"1.1";

    Entry *entry = [NSEntityDescription insertNewObjectForEntityForName:@"Entry"
                                             inManagedObjectContext:[AppDelegate applicationDelegate].managedObjectContext];

    entry.version = existingEntry.version;

    [[AppDelegate applicationDelegate].managedObjectContext deleteObject:entry];

    i++;
}

But this runs out of memory after going through a certain amount of data. This also happens if i only take the first 'result' and don't go through the entire array, so the running out of memory doesn't seem to be a result of going through the results.
How can i do this without running out of memory?

A: Suppose your count is 1000 - some big number. Break that into a smaller one - like 100. Then in the big loop, set another counter, and use an autorelease pool around the smaller loop, so when you leave that inner loop will drain the pool. This works assuming you have no strong references to the objects in the inner loop (but might help even in that case).
EDIT: code (not tested or compiled)
int total = results.count;
while (total) {
    int count = total < 100 ? total : 100;
    total -= count;

    @autoreleasepool {
        while(count--) {
                Entry *entry = [results objectAtIndex:i];

                entry.version = @"1.1";

                Entry *entry = [NSEntityDescription insertNewObjectForEntityForName:@"Entry"
                                                         inManagedObjectContext:[AppDelegate applicationDelegate].managedObjectContext];

                entry.version = existingEntry.version;

                [[AppDelegate applicationDelegate].managedObjectContext deleteObject:entry];

            }
        }
}

