第一種: 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)使用的提示。。如果有使用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 可解決}];
}