我创建了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