Xcode Instruments claims that the below code results in memory leak. As far as I understand, the following happens when assigning a property:
* The old value is autoreleased
* The new value is retained
* The new value is assigned obviously
With that it mind, how come I have a memory leak and how do I resolve it?
"TestProjectViewController.h":
#import <UIKit/UIKit.h>
@interface TestProjectViewController : UIViewController {
NSMutableArray* array;
}
@property (nonatomic, retain) NSMutableArray* array;
@end
"TestProjectViewController.m":
#import "TestProjectViewController.h"
@implementation TestProjectViewController
@synthesize array;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
for(int i = 0; i < 5; i++) {
self.array = [[NSMutableArray alloc] init];
[self.array addObject:@"Hello world #1"];
[self.array addObject:@"Hello world #2"];
}
}