I have a static method in a Utilities class:
+ (Division *) getDefaultDivision
{
Division *defaultDivision = [[Division alloc] init];
defaultDivision.Id = 0;
defaultDivision.name = @"Accounting";
defaultDivision.slug = @"accounting";
return defaultDivision;
}
And in my ViewController I do something like:
Division *div = [[Division alloc] init];
div = [Utilities getDefaultDivision];
But when I analyze, it says “Potential leak of an object allocated on line x and stored into defaultDivision”.
If I use:
Division *defaultDivision = [[[Division alloc] init] autorelease];
it works once, but when I use it again, it crashes.
Just wondering what the proper thing is to do here?
If this is your real code;
You’re first allocating a Division and saving it in div, then you’re getting a new one from getDefaultDivision storing that in div too without releasing the first one.