memory leak issue
am getting memory leak in the following code..pls help me to solve this..
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//iPad specific code.
universalApp=1;
NSLog(@"ipad started.......");
// Override point for customization after application launch
window.frame = CGRectMake(0, 0, 768, 1004);
//window.frame = CGRectMake(0, 0,320,460);
mainPageController = [[MainPageController alloc] initWithNibName:@"MainPageController" bundle:nil];
// [开发者_开发知识库mainPageController.view setFrame:CGRectMake(0, 20, 320, 460)];
[window addSubview:mainPageController.view];//memory leak
[window makeKeyAndVisible];
I don't see a leak there, assuming you're releasing mainPageController
in -applicationWillTerminate:
or your app delegate's -dealloc
. What's the problem?
You should release mainPageController if you dont release it in -applicationWillTerminate: or your app delegate's -dealloc like Noah Witherspoon says.
So, you should modify the code like this if you aren't using ARC:
mainPageController = [[[MainPageController alloc] initWithNibName:@"MainPageController" bundle:nil] autorelease];
or
[window addSubview:mainPageController.view];//memory leak
[mainPageController release];
[window makeKeyAndVisible];
And of course, you should read the Advanced Memory Management Programming Guide
精彩评论