在collectionView的方法中:
__weak typeof(self)weakSelf = self;
cell.deletHeaderBlock = ^{
__strong typeof(weakSelf)strongSelf = weakSelf;
UIView*view = [collectionView cellForItemAtIndexPath:selectIndex]
};
在cell的block里面直接使用collectionView會(huì)造成循環(huán)引用,Xcode的內(nèi)存檢測(cè)工具也不能檢測(cè)到,控制器的dealloc方法也能夠正常執(zhí)行,但是內(nèi)存不會(huì)釋放掉,使用strongSelf.collectionView代替直接使用collectionView便可解決問(wèn)題.
另外由于block的變量捕獲機(jī)制,當(dāng)在block中使用局部對(duì)象時(shí),如果這個(gè)對(duì)象占用內(nèi)存很大,會(huì)導(dǎo)致內(nèi)存占用過(guò)高,可以在block外面先創(chuàng)建一個(gè)變量記錄要使用的值,在block內(nèi)部使用這個(gè)變量,可以減少內(nèi)存占用。
UIImageOrientation orientation = currentUseVirtaulHeaderModel.imgOrientation;
dispatch_source_set_event_handler(self.timer, ^{
[self playVirtualHeaderWithPixelBufferArray:pixelBufferArray imgOrentation:orientation];
});