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.
Check how you declare the property
currentDivisionin your app delegate. If it isassign(which I suppose, since you are retaining it before assigning through the property) then the original value you assigned to it:will not get
releasedwhen you execute:hence, the object you created in the app delegate will leak. Do a release manually and check whether the analyzer keeps complaining:
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:where you should not do the retain manually.