1
的BitmapImage泄漏內存時CreateOptions是什麼,但DelayCreation,是擺在視覺樹(在一個圖像或圖像刷)WP7 BitmapImage的內存泄漏時CreateOptions不DelayCreation
我與SDK 7.1見狀在模擬器上以及手機(HTC泰坦) 步驟:
- 打開新的WP項目
- 開始在App.xaml.cs新dispatchertimer,打印內存使用(DeviceStatus)每秒和做GC.Collect的() 。 (考慮newing了計算出的尺寸的字節數組爲比(MemoryUsageLimit少一點 - CurrentMemoryUsage))
- 添加一個StackPanel名爲ImagePanel內部的ContentPanel
- 添加2個按鈕的ContentPanel(1用於創建和加入10個圖像 與代碼和一個ImagePanel以清除ImagePanel的孩子)
- 查找高分辨率圖像(只是這樣的內存使用情況是很容易 可見),並放置在您的本地IIS
當按鈕1被點擊寫:
Random rand = new Random(); for(int i=0 ; i<10 ; i++) { //use 192.168.55.100 instead of localhost when running on the phone //to be able to see traffic in fiddler.Change localhost to machinename for the emulator var uri = "http://localhost/images/bigimage.jpg?tc=" + rand.Next(Int32.MaxValue); var bitmap = new BitmapImage { UriSource = new Uri(uri, UriKind.RelativeOrAbsolute), CreateOptions = BackgroundCreation //or None or DelayCreation }; ImagePanel.Children.Add(new Image { Source = bitmap }); }
當按鈕2被點擊寫:
ImagePanel.Children.Clear(); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect();
嘗試用CreateOptions的所有變化,看在內存中的差異。 繼續添加和刪除元素,並查看您將使用哪個CreateOption獲取OutOfMemoryException。
有人可以驗證這一點嗎?
這是什麼問題? – thumbmunkeys 2012-04-22 16:29:18
@atomaras - 正因爲你要求它消失並不意味着GC真的會這樣做。這裏沒有泄漏。 – 2012-04-22 17:57:36
Isnt得到OutOfMemoryException是一個很好的指標,它不可收集? – atomaras 2012-04-22 18:46:31