Q:

iOS: Memory Leak

In a Utilities class, I have the following method:
+ (Division *) getNationalDivision
{
    Division *defaultDivision = [[[Division alloc] init] autorelease];
    defaultDivision.Id = 0;
    defaultDivision.name = @"National";

    return defaultDivision;
}

I have a division allocted in my app delegate to store the division throughout the app, so in one of my view controllers I have:
appDel.currentDivision = [[Utilities getNationalDivision] retain];

In the app delegate .h I have:
@property (nonatomic, retain) Division *currentDivision;

In the app delegate .m I have:
currentDivision = [[Division alloc] init];

When I analyze, I get potential leak of an object that points to the above line.  Any ideas?  If I dont retain the national division, it doesnt work.  Also, just to note, everything works fine.  I just want to make sure I am not leaking something.

A:

Check how you declare the property currentDivision in your app delegate. If it is assign (which I suppose, since you are retaining it before assigning through the property) then the original value you assigned to it:
 currentDivision = [[Division alloc] init];

will not get released when you execute:
 appDel.currentDivision = [[Utilities getNationalDivision] retain];

hence, the object you created in the app delegate will leak. Do a release manually and check whether the analyzer keeps complaining:
[app.currentDivision release];

This only makes sense in case your property is declared as assign.
In case it is declared as retain, then the fault is on line:
 appDel.currentDivision = [[Utilities getNationalDivision] retain];

where you should not do the retain manually.

