0

The Instruments tells me that this piece of code has a leak. However, I am pretty sure I have released it later on. Can anyone tell me what's going on here?

- (void) addReminderEntry{
    DataEntryController* item = [[DataEntryController alloc] initWithEntryType:REMINDER]; // it says that the leak was instantiated here
    item.delegate = self;
    [[self navigationController] pushViewController:item animated:YES];
    [item setEditing:YES animated:YES];
    [item release];// this is the place I release it
}

Thanks

Winston Chen
  • 6,799
  • 12
  • 52
  • 81
  • 1
    You don't provide enough information. First, what is "REMINDER"? Second, you don't include the initWithEntryType: code or what type of object Instruments specifically said was leaked (was it definitely a DataEntryController instance?). – Joshua Nozzi Dec 08 '10 at 15:52
  • 1. The REMINDER is an enum, so it should not be the reason to leak. 2. Yes, Instruments says that it's definitely the DataEntryController instance. Thanks for replying. – Winston Chen Dec 09 '10 at 00:07

3 Answers3

1

More than likely it has to do with something not being released within the DataEntryController class. Make sure you are releasing all your properties/etc within that class.

DerekH
  • 860
  • 5
  • 11
1

Leaks tells you only where memory was allocated, what it cannot tell you is where to put the code that should have released it to start with!

So this is saying that you made a view controller, and it was still around in memory after you finished with it. Yes you release the VC in that code, but only after you present it - which means the navigation controller has retained it, and possibly other things. It only gets deallocated when the final release is called.

The main culprit for view controllers not being released is usually having the view controller set itself as a delegate for something it retains, and then not undoing that when the view controller goes offscreen. If your view controller is a delegate of something that retains it, it's never going to be deallocated.

Kendall Helmstetter Gelner
  • 74,769
  • 26
  • 128
  • 150
0

It turns out that this is caused by this constructor:

- (DataEntryController*) initWithEntryType:(DataType) eType{
    DataEntryController* item = [[DataEntryController alloc] init];//<- here
    item.entryType = eType;
    item.allowEdit = YES;
    return item;
}

Apparently iOS adds retain 1 to each constructor with an initial 'init'.

It works fine after switching to:

DataEntryController* item = [super init];
Winston Chen
  • 6,799
  • 12
  • 52
  • 81