开发者

Where is memory leak in this small function

Instruments says I have leak in this function. I am new to Obj-C so pardon for missing something obvious besides I am not sure if I am doing everything right here.

(void) selectList:sender {
NSMutableString *nibName = @"myController";
MyOwnController *study = [[MyOwnController alloc] initWithNibName:nibName bundle:nil];
stud开发者_JS百科y.title = @"Fundamentals";
study.listNameToLoad = @"funds";
[self.navigationController pushViewController:study animated:YES];
[nibName release];
[study.title release];
[study.listNameToLoad release];
[study release];
study = nil;
}

Related questions. Once you do pushViewController should you always do a release on the controller you just pushed on the stack ?


You should read this first.

In summary, you release only if you create or copy. You have released quite a few variables which you haven't created/copied and is not your responsibility to release. You should hence not release nibName, study.title & study.listNameToLoad.

Again, You should release the 'title' and 'listNameToLoad' properties within the controller's dealloc method.

As for your related question, you can release the controller only if you don't need the reference any more. If you do choose to keep the reference, you need to release the reference later when you don't need it any more.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜