作者lab0424 (刻骨銘心...)
看板MacDev
標題[問題] MPMoviePlayerController Leak!!!
時間Tue Aug 23 18:50:50 2011
大大們好~
這裡有個leak問題想問問看有沒有大大知道的
程式簡易關鍵代碼:
mp = [[MPMoviePlayerController alloc] initWithContentURL:strurl];
[mp setControlStyle:MPMovieControlStyleDefault];
[mp prepareToPlay];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerLoadStateChanged:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
=====> 然後在moviePlayerLoadStateChanged裡面
[mp play];
=====> 而moviePlayBackDidFinish裡面執行
if (mp)
{
[mp pause];
mp.initialPlaybackTime = -1;
[mp stop];
mp.initialPlaybackTime = -1;
[mp release];
mp = nil;
}
一旦關閉正在播放的影片,於是執行到moviePlayBackDidFinish中
但卻發現:
if (mp)
{
NSLog(@"test(0) mp retain count=%d", [mp retainCount]); //=>retain count是1
[mp pause];
NSLog(@"test(1) mp retain count=%d", [mp retainCount]); //=>retain count是2
mp.initialPlaybackTime = -1;
[mp stop];
NSLog(@"test(2) mp retain count=%d", [mp retainCount]); //=>retain count是5
mp.initialPlaybackTime = -1;
[mp release];
mp = nil;
}
想問問有大大們
(1)為什麼執行pause時, retain count從1變成2, 而執行stop時retain count從2變成5
(2)怎麼樣可以避免這個leak
感謝大大們關注!!!
感謝!!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.248.161.28
1F:→ yllan:正常狀況下你用不到 retainCount. 這也不代表他 leak 08/23 21:09
2F:→ lab0424:因為觀察Instruments裡面的activity monitor發現leak 08/23 23:33
3F:→ lab0424:每次播影片會上升1M多的記憶體用量, 然而都沒下降下來! 08/23 23:34
4F:→ lab0424:所以才開始觀察member的retain count 08/23 23:35
5F:推 offname:在實機上用 intrument 找一下 leak 沒有的話可以暫時不管 08/24 07:19
6F:→ zonble:先跑一下 Build and Analyze 吧 08/24 10:55
7F:→ zonble:Retain Count 增加不代表 Memory Leak 08/24 10:56
8F:→ zonble:先檢查一下會不會是漏在其他地方 08/24 10:56