views:

29

answers:

1

I am importing a good amount of data into my application using Core Data like so:

for (int i = 0; i < [items count]; i++) 
{
    Client *entity = (Client*) [NSEntityDescription insertNewObjectForEntityForName:@"Client" inManagedObjectContext:managedObjectContext];
    [entity setCompanyName:[[items objectAtIndex:i] objectForKey:@"CompanyName"]];
    //* bunch of other fields

    NSError *error;

    if (![managedObjectContext save:&error]) {
        // Handle the error.
        NSLog(@"%@",error);
    }   
}

What do I need to be releasing here? should I be doing [entity release]?

+2  A: 

As the documentation says:

insertNewObjectForEntityForName:inManagedObjectContext:
Despite the presence of the word “new” in the method name, in a reference counted environment you are not responsible for releasing the returned object.

So the answer is no, you don't need to release the entity variable.

Note this is the standard. When using a convenience method, returned instances are auto-released by convention, so you don't need to care about them, unless you explicitly retain them, of course.

Macmade
thank you sir, that's what I needed to know
Slee
You're welcome : )
Macmade