[問題] MPMoviePlayerController Leak!!!

看板MacDev作者 (刻骨銘心...)時間14年前 (2011/08/23 18:50), 編輯推噓1(107)
留言8則, 4人參與, 最新討論串1/1
大大們好~ 這裡有個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
正常狀況下你用不到 retainCount. 這也不代表他 leak
08/23 21:09, 1F

08/23 23:33, , 2F
因為觀察Instruments裡面的activity monitor發現leak
08/23 23:33, 2F

08/23 23:34, , 3F
每次播影片會上升1M多的記憶體用量, 然而都沒下降下來!
08/23 23:34, 3F

08/23 23:35, , 4F
所以才開始觀察member的retain count
08/23 23:35, 4F

08/24 07:19, , 5F
在實機上用 intrument 找一下 leak 沒有的話可以暫時不管
08/24 07:19, 5F

08/24 10:55, , 6F
先跑一下 Build and Analyze 吧
08/24 10:55, 6F

08/24 10:56, , 7F
Retain Count 增加不代表 Memory Leak
08/24 10:56, 7F

08/24 10:56, , 8F
先檢查一下會不會是漏在其他地方
08/24 10:56, 8F
文章代碼(AID): #1EKuODjg (MacDev)
文章代碼(AID): #1EKuODjg (MacDev)