Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 675
Jesse Avatar asked Feb 28 '26 20:02

Jesse


1 Answers

The retain is done by the synthesized property accessor method. Remove it.

like image 104
Nikolai Ruhe Avatar answered Mar 03 '26 08:03

Nikolai Ruhe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!