开发者

memory leak issue

开发者 https://www.devze.com 2023-02-09 05:52 出处:网络
am getting memory leak in the following code..pls help me to solve this.. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

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

0

精彩评论

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