我創建了WPF
windows應用程序,使用網格顯示更多圖像。當我運行我的application.exe
時,我的下面的代碼得到OutOfMemory Exception
。Outmamemory異常當bitmapimage配置
byte[] buffer = File.ReadAllBytes(path);
File.Delete(path);
if (buffer == null)
return null;
using (MemoryStream mStream = new MemoryStream(buffer))
{
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.StreamSource = mStream;
bi.EndInit();
bitmap = bi;
bitmap.Freeze();
mStream.Close();
mStream.Dispose();
}
我發現從計算器一些解決方案,改變了我的代碼如下以下,
BitmapImage image = new BitmapImage();
{
image.BeginInit();
// image.CreateOptions = BitmapCreateOptions.n;
image.CacheOption = BitmapCacheOption.OnLoad;
image.UriSource = new Uri(path);
image.EndInit();
File.Delete(path);
bitmap = image;
image.UriSource = null;
image = null;
}
但這種代碼變得異常爲image used by another process
或cant open from locked file
。
我完全困惑爲什麼我的應用程序經常由OutOfMemory或used by another process
異常引起?
你可以看看波紋管鏈接,提高RAM性能比較http://social.msdn.microsoft.com/Forums/en -US/5a13a184-ef47-423a-89ed-7ca1b8a0aaf8/build-your-own-memory-optimizer-with-c?forum = netfxnetcom – KVK
你也可以看看你的文章並回答這個問題 - 「我的文章格式很好?我想從其他人那裏閱讀這些帖子嗎?「 –
@KVK即使我嘗試鏈接code.its減少內存大小罰款,但即使經常得到相同的異常。 – MMMMS