[英]Out of Memory with BitmapImage
I'm trying to developp an app to take and print photos with Visual Studio 2013. 我正在尝试开发使用Visual Studio 2013拍摄和打印照片的应用程序。
The app is divide in 2 project : 该应用程序分为2个项目:
First the client, it take 4 photos and send their pathfiles. 首先,客户端需要拍摄4张照片并发送其路径文件。
The second is the server. 第二个是服务器。 When there is a connection, he show the 4 photos. 建立连接后,他会显示4张照片。 Then the user can choose a frame, a quantity and print his photos. 然后,用户可以选择框架,数量并打印其照片。
There is a problem with the loading: 加载有问题:
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;
I've try with "BitmapCacheOption.OnDemand". 我尝试使用“ BitmapCacheOption.OnDemand”。 When the program start, memory consumption is 3Go. 程序启动时,内存消耗为3Go。 After few minutes, it increase to 6Go. 几分钟后,它增加到6Go。
When the outofmemoryexception is thrown, it comes to PresentationCore.dll 抛出outofmemoryexception时,它出现在PresentationCore.dll中
I've looking ofr the consumption, and at each loop of the program, the comsumption increase of 0,4Go. 我一直在寻找消耗量,并且在程序的每个循环中,消耗量增加了0.4Go。
WIthout show the photos, the app is stable. 不显示照片,应用程序稳定。
I've try with Bitmap and BitmapImage, GC.Collect and DeleteObject of gdi32.dll, the problem is the same. 我尝试使用gdi32.dll的Bitmap和BitmapImage,GC.Collect和DeleteObject,问题是相同的。
Is there a way to dispose all the resources? 有没有办法处置所有资源?
Sorry for my english 对不起我的英语不好
You are caching the whole bitmap in memory - BitmapCacheOption.OnLoad. 您正在将整个位图缓存在内存中-BitmapCacheOption.OnLoad。 Try using None or OnDemand instead of OnLoad. 尝试使用None或OnDemand代替OnLoad。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.