controller 不能釋放,不走dealloc方法的4種可能

第一種: controller中使用了計(jì)時(shí)器 NSTimer 使用后沒(méi)有銷毀 導(dǎo)致循環(huán)引用

self.playerTimer = [NSTimerscheduledTimerWithTimeInterval:1target:selfselector:@selector(playProgressAction)userInfo:nilrepeats:YES];

使用后記得銷毀

[_playerTimerinvalidate];

_playerTimer =**nil**;

第二種:協(xié)議delegate 應(yīng)該使用weak修飾,否則會(huì)引起循環(huán)引用 不能釋放內(nèi)存

@property (nonatomic,weak)id<huifuDelegate>huifudelegate;

第三種:使用到block的地方,,block回調(diào)中不能直接使用self 否則可能引起循環(huán)引用。

__weak****typeof(self) weakSelf =self;

_audioStream.onCompletion=^(){

    [weakSelf nextButtonAction];

};

第四種:

對(duì)于前三種 大家可能都知道,,我發(fā)現(xiàn)一個(gè)會(huì)導(dǎo)致controller不能釋放的情況,,很詭異,,pop后不走dealloc 再push進(jìn)來(lái)會(huì)走一次dealloc..這種情況是我接手的工程中出現(xiàn)的問(wèn)題,,不僅不能釋放 ,,如果這個(gè)controller中有音頻 視頻的錄制,,應(yīng)用退入后臺(tái)會(huì)出現(xiàn)麥克風(fēng)后臺(tái)使用的提示。
image

。如果有使用AirPlay 播放音頻 ,,也會(huì)對(duì)AirPlay的時(shí)間顯示產(chǎn)生干擾。。當(dāng)然這都是沒(méi)釋放內(nèi)存引起的。。。。。。。

具體的情況如下,

有ViewController和ceshiViewController ViewController要push到ceshiViewController

import "ViewController.h"

import "ceshiViewController.h"

@interfaceViewController (){

ceshiViewController *ceshiVC;// 使用實(shí)例變量聲明的時(shí)候,,我是不怎么這樣寫

}

  • (void)action{

    ceshiVC = [[ceshiViewControlleralloc]init];///這樣寫就出問(wèn)題了

    [self.navigationControllerpushViewController:ceshiVCanimated:YES];

}

/////////////==============///////////////////

import "ceshiViewController.h"

@interfaceceshiViewController ()

@end

@implementation ceshiViewController

  • (void)dealloc{

    NSLog(@"---釋放");

}

controller 返回后不會(huì)釋放。。。。。。。。

5.。。。。項(xiàng)目中遇到的不走dealloc情況

@interface TopicDetailViewController (){

NSInteger videoType;

}

  • (void)addFooterData{

    __weak TopicDetailViewController *weakself = self;

    self.TopicDetailTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{

      [weakself loadDataWithtype:videoType];  
    
      /// 在這里使用videoType后 不走dealloc 換成屬性創(chuàng)建,,使用weakself.videoType 可解決
    

    }];

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容