内存泄漏问题

时间:2011-02-09 12:53:44

标签: iphone memory-management

在以下代码中出现内存泄漏...请帮我解决这个问题..

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];

2 个答案:

答案 0 :(得分:0)

假设您在mainPageController或您的应用代表的-applicationWillTerminate:中发布-dealloc,我认为没有泄漏。有什么问题?

答案 1 :(得分:0)

如果您不在 -applicationWillTerminate:或您的应用委托的 -dealloc 中发布主页控件,则应该发布 NoPage Witherspoon < / strong>说。

因此,如果您不使用ARC,则应修改此类代码:

mainPageController = [[[MainPageController alloc] initWithNibName:@"MainPageController" bundle:nil] autorelease];

[window addSubview:mainPageController.view];//memory leak
[mainPageController release];
[window makeKeyAndVisible];

当然,您应该阅读Advanced Memory Management Programming Guide