繁体   English   中英

appDelegate方法,调用者此时尚未拥有的对象的引用计数不正确地递减

[英]appDelegate method with Incorrect decrement of the reference count of an object that is not owned at this point by the caller

我遇到了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对象 方法返回具有+0保留计数的Objective-C对象 以及调用者此时不拥有的对象的引用计数的错误减少 调用者此时尚未拥有的对象的引用计数的错误减少

我为什么会收到此泄漏? 我要重新分配appDelegate对象吗?

我没有在该accessor(appDelegate)的返回值上调用release,也没有将其设置为nil,我该如何解决此泄漏?

提前致谢

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

iPhone正确使用Application Delegate

例如,在您的代码中:

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

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

至于您的内存泄漏,请检查您的应用程序委托动画执行动画停止回调时是否保留了所有内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM