首先在非ARC下:
testButton *_tempBtn = [[testButton alloc]initWithFrame:CGRectMake(0, 200, 200, 200)];
[self.view addSubview:_tempBtn];
//此時_tempBtn的引用計數爲2
然後在ARC下:
testButton *_tempBtn = [[testButton alloc]initWithFrame:CGRectMake(0, 200, 200, 200)];
[self.view addSubview:_tempBtn];
//此時_tempBtn的引用計數爲2
[_tempBtn addTarget:self action:@selector(CPCarPoolingFeeVC:paidSuccessfullyOrder:) forControlEvents:UIControlEventTouchUpInside];
//addTarget不會增加_tempBtn的retainCount(此時還是2),addTarget也不會增加self的引用計數
//addTarget是將target加入_tempBtn對象的NSSet(推測根據:allTarget函數)中,所以正常也不會增加_tempBtn的retainCount。
[[NSNotificationCenter defaultCenter] addObserver:_tempBtn selector:@selector(applicationLaunchedWithUrl:) name:@"asdasda" object:nil];
//addObserver不會增加_tempBtn的retainCount(此時還是2)
當self這個Controller被釋放的時候會先走controller的dealloc此時_tempBtn存在,在這之後會走_tempBtn的dealloc