[問題] MPMoviePlayerController Leak!!!
大大們好~
這裡有個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
→
08/23 21:09, , 1F
08/23 21:09, 1F
→
08/23 23:33, , 2F
08/23 23:33, 2F
→
08/23 23:34, , 3F
08/23 23:34, 3F
→
08/23 23:35, , 4F
08/23 23:35, 4F
推
08/24 07:19, , 5F
08/24 07:19, 5F
→
08/24 10:55, , 6F
08/24 10:55, 6F
→
08/24 10:56, , 7F
08/24 10:56, 7F
→
08/24 10:56, , 8F
08/24 10:56, 8F
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章