2011-02-09 23 views
0

正在逐渐内存泄漏以下code..pls帮我解决这个..内存泄漏问题

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

是如何你测量内存泄漏?你有没有尝试过构建和分析?或者你在使用泄漏工具吗? – 2011-02-09 13:11:21

+0

我使用了泄漏工具。 – Madhumitha 2011-02-09 13:19:30

回答

0

我没有看到一个有泄漏,假设你在-applicationWillTerminate:或你的释放mainPageController应用程序代理的-dealloc。有什么问题?

0

您应该释放mainPageController如果你不释放在-applicationWillTerminate:或应用程序委托的-dealloc诺亚·威瑟斯彭说。

所以,你应该如果你不使用ARC修改这样的代码:

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

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

,当然还有,你应该阅读Advanced Memory Management Programming Guide