【问题标题】:appDelegate method with Incorrect decrement of the reference count of an object that is not owned at this point by the caller调用者此时不拥有的对象的引用计数的不正确递减的 appDelegate 方法
【发布时间】:2012-10-04 12:26:48
【问题描述】:

我遇到了带有 incorrect decrement of RC to +0 的 SO 帖子,但没有一个是 appDelegate 方法(据我所知无法保留代表

以下是我有内存泄漏的代码

    iPlayerAppDelegate *appDelegate = (iPlayerAppDelegate *)[[UIApplication sharedApplication] delegate];
    int currentTabIndex = appDelegate.tabcontroller.tabBarController.selectedIndex ;

    UIButton *btn = (UIButton *)sender;


    pageItem* selectedItem = nil;
    selectedItem = [appDelegate.pageData.pageItems objectAtIndex:btn.tag];

    appDelegate.bStatusValue = FALSE;

    if(pageInfo.removeCaptureFile)
    {
        [appDelegate.commonUtils removeFileFromPath:@"snap.jpeg"];
        [appDelegate.commonUtils removeFileFromPath:@"prevSnap.jpeg"];
    }

    if (appDelegate.launchTimer &&[appDelegate.launchTimer isValid]) 
    {
        [appDelegate.launchTimer invalidate];
        appDelegate.launchTimer = nil;          
       // appDelegate.timerFlag = NO;

    }

    NSArray *viewarray = [self.view subviews];

    for(int index=0;index< viewarray.count;index++)
    {

        UIView *view = [viewarray objectAtIndex:index];
        if([view  isMemberOfClass:[UITextField class]] || [view  isMemberOfClass:[UITextView class]])   
        {
            [view resignFirstResponder];
            [view removeFromSuperview];
        }

        if([view  isMemberOfClass:[scrollwinView class]])  
        {
            scrollwinView* scrollView = (scrollwinView*) view;
            [scrollView stopTimer];
        }

    }

    if(appDelegate.tabsupport)
    { //to remove the cached view from stack after pressing back
        CSNavigationController *navcon= (CSNavigationController*)appDelegate.tabcontroller.tabBarController.selectedViewController;
        [navcon removeViewData:pageInfo.screenId];
    }

    int currentscrid=pageInfo.screenId; 
    clrScreenId = pageInfo.clrScreenId;

    if (appDelegate.connMgr) 
    {               
        [appDelegate.connMgr closeHttpStream];
        //[connMgr release];        
        appDelegate.connMgr = nil;
        appDelegate.connectionstatus = FALSE;


        if(appDelegate.initAnimation.startId == 5)      
        {
            appDelegate.transition = NO ;
            [appDelegate readPageData:currentscrid isBack:NO ];
            appDelegate.transition = YES;
            return ;
        }

        [appDelegate stopAnimation];

这里是内存泄漏的快照方法返回一个带有+0保留计数的Objective-C对象,并且调用者此时不拥有的对象的引用计数不正确递减

为什么我会得到这个泄漏?我要重新分配 appDelegate 对象吗?

我没有在那个访问器(appDelegate)的返回值上调用release,也没有将它设置为nil,我应该如何修复这个泄漏?

提前致谢

【问题讨论】:

    标签: iphone ios memory-leaks appdelegate


    【解决方案1】:

    我认为您应该阅读有关正确使用应用程序委托的帖子:

    iPhone proper usage of Application Delegate

    例如,在您的代码中:

    selectedItem = [appDelegate.pageData.pageItems objectAtIndex:btn.tag];
    

    看起来很乱。一个可能更好的解决方案可能是使用单例设计模式。

    至于您的内存泄漏,可能会检查您的应用委托动画执行动画停止回调时是否没有保留任何内容。

    【讨论】:

    • 我知道不应该保留委托,我没有保留委托..如果您能弄清楚我为什么会泄漏,请发布解决方案
    猜你喜欢
    • 2011-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多