views:

118

answers:

2

Hi

I have the following piece of code and when I use Instruments/Object Allocations, it tells me that there is a leak there (which goes down to sqlite3MemMalloc). Is there something that I should release?

if (![managedObjectContext save:&error]) {
  NSLog(@"Error while saving.");
}

The save works well and doesn't trigger an error.

+1  A: 

The leak is most likely in one of the managed objects being saved and it just shows here. If you look at the stack in Instruments you can probably see the leaking object. Since it only shows up at save, it's probably in validation code.

TechZen
Thanks for your answer. What do you mean by "verification code" ?Also, from what I tried, I seems that managed objects are autoreleased.
Kamchatka
ManagedObjects themselves are retained/released by the context but any object they create themselves can leak. For example, if you had a custom method that initialized a string but did not release it.
TechZen
Sorry "verification" should be "validation". It's the methods that are called right before a managed object is save to ensure that an attribute/property is in the correct state before saving. By default the methods take the form of `validatePropertyName:error:`.
TechZen
+1  A: 

Do you have any subclasses of your NSManagedObject instances?

When you set a value into your NSManagedObject instances do you then release your ownership of them? For example if you were do to the following code:

NSString *someString = [[NSString alloc] initWithString:@"Blah"];
[myManagedObject setValue:someString forKey:@"stringValue"];

You would be leaking memory because you are still owning that NSString. That is what TechZen is referring to above.

Marcus S. Zarra