2015-04-23 35 views
0

我想developp一個應用程序來拍攝和打印照片與Visual Studio 2013年內存與BitmapImage的

應用程序是在2分項目:

  • 首先在客戶端,它拍4張照片併發送他們的路徑文件。

  • 第二個是服務器。當有連接時,他會顯示4張照片。 然後用戶可以選擇一個框架,數量並打印他的照片。

有一個與裝載一個問題:

  BitmapImage _img1 = new BitmapImage(); 
      _img1.BeginInit(); 
      _img1.CacheOption = BitmapCacheOption.OnLoad; 
      _img1.UriSource = new Uri(_images[0]); 
      _img1.EndInit(); 
      img1.Source = _img1; 

      BitmapImage _img2 = new BitmapImage(); 
      _img2.BeginInit(); 
      _img2.CacheOption = BitmapCacheOption.OnLoad; 
      _img2.UriSource = new Uri(_images[1]); 
      _img2.EndInit(); 
      img2.Source = _img2; 

      BitmapImage _img3 = new BitmapImage(); 
      _img3.BeginInit(); 
      _img3.CacheOption = BitmapCacheOption.OnLoad; 
      _img3.UriSource = new Uri(_images[2]); 
      _img3.EndInit(); 
      img3.Source = _img3; 

      BitmapImage _img4 = new BitmapImage(); 
      _img4.BeginInit(); 
      _img3.CacheOption = BitmapCacheOption.OnLoad; 
      _img4.UriSource = new Uri(_images[3]); 
      _img4.EndInit(); 
      img4.Source = _img4; 

我嘗試用 「BitmapCacheOption.OnDemand」。程序啓動時,內存消耗爲3Go。幾分鐘後,它增加到6Go。

當OutOfMemoryException異常被拋出,它涉及到PresentationCore.dll中

我看OFR消費,並在程序,0,4Go的罪耗增加每個循環。

無法顯示照片,該應用程序是穩定的。

我試着用Bitmap和BitmapImage,GC.Collect和DeleteObject的gdi32.dll,問題是一樣的。

有沒有辦法處理所有的資源?

對不起,我的英語

+1

您多久創建一次這些圖片?你是否積極處置它們? – BrokenGlass

+0

不確定它是否會影響您的問題,但是在您鍵入'_img3.CacheOption = BitmapCacheOption.OnLoad;''_img4'部分的代碼中 – NLindbom

+0

您是否正在處理任何位圖?否則,正在使用的內存量將會增加 – TheLethalCoder

回答

0

您緩存在內存中的整個位圖 - BitmapCacheOption.OnLoad。嘗試使用無或OnDemand而不是OnLoad。