Image vs Border vs Rectangle来克服内存泄漏 [英] Image vs Border vs Rectangle to overcome memory leaks

查看:68
本文介绍了Image vs Border vs Rectangle来克服内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在开发一个信息亭,在某个页面上它会显示所需数据和图像的列表(从mysql检索并转换字节用于显示)大约20个图像,其原始大小是动态分辨率。一些图像宽度是1200px,大约800px,大约2000px。



现在,我已经使用所有三个图像,边框和矩形作为测试,看看哪一个是更好的公羊消费。因为如果我显示数据A并返回选择页面并重复显示数据A,我的ram有时会跳得很高。它会增加,直到max ram和程序变为挂起和崩溃。即使我只是做了一次这个过程,内存也很慢,以减少回来。



规格:

1)CPU:i5

2)内存:4GB

3)操作系统:Win8 64位

4)显示:1080x1920(垂直方向)

5)工具:VS2010 WPF VB.NET



我不知道如何解决这个问题,因为客户总是要求克服内存已满并使程序挂起一定的时间(这意味着连续显示图像文件)



问题:有没有最好的方法来克服图像上的内存泄漏



以下是我转换字节和显示图像的方法: -

BORDER

Hi all,

I'm developing a information kiosk which at certain page it will show list of required data and image(retrieve from mysql and convert the bytes for display) around 20 images which original size is dynamic resolution. Some image width is 1200px, some 800px, some 2000px.

Now, I've been use all three image,border and rectangle as a test to see which one is better ram consume. Because my ram sometimes jump high if I show for data A and going back to selection page and repeating process to show data A back again. It will increase until max ram and program become hang and crash. Even I just do the process once, the memory is very slow to reduce back.

Specification:
1) CPU: i5
2) RAM: 4GB
3) OS: Win8 64Bit
4) Display: 1080x1920 (Vertical Orientation)
5) Tools: VS2010 WPF VB.NET

I don't know how to solve this problem since customer always asking to overcome memory is full and make the program hang at certain time(which mean when continuously displaying image file)

Question: Is there any best way to overcome memory leaks on image

Below is what I do to convert bytes and display image:-
BORDER

view_imgbyte= arr_info.Item(0).arrImage
If Not (IsNothing(view_imgbyte)) Then
    Using stream = New MemoryStream(view_imgbyte)
        Dim bitmap = New BitmapImage()
        bitmap.BeginInit()
        bitmap.StreamSource = stream
        bitmap.CacheOption = BitmapCacheOption.OnLoad
        bitmap.EndInit()
        bitmap.Freeze()
        stream.Dispose()
        img_file.ImageSource = bitmap
    End Using
Else
    img_file.ImageSource = Nothing
End If





IMAGE



IMAGE

view_imgbyte= arr_info.Item(0).arrImage
If Not (IsNothing(view_imgbyte)) Then
    Using stream = New MemoryStream(view_imgbyte)
        Dim bi As New BitmapImage()
        bi.BeginInit()
        bi.StreamSource = stream
        bi.CacheOption = BitmapCacheOption.OnLoad
        bi.EndInit()
        bi.Freeze()
        stream.Dispose()
        Dim src As ImageSource = bi
        img_file.Source = src
        img_file.Width = 800
    End Using
Else
    img_file.ImageSource = Nothing
End If





RECTANGLE



RECTANGLE

view_imgbyte= arr_info.Item(0).arrImage
If Not (IsNothing(imgbyte)) Then
    Using stream = New MemoryStream(imgbyte)
        Dim bitmap = New BitmapImage()
        bitmap.BeginInit()
        bitmap.StreamSource = stream
        bitmap.CacheOption = BitmapCacheOption.OnLoad
        bitmap.EndInit()
        bitmap.Freeze()
        imgBrush.ImageSource = bitmap
        stream.Dispose()
        img_file.Fill = imgBrush
        img_file.Stretch = Stretch.Fill
    End Using
End If





感谢任何帮助。谢谢



Appreciate any help. Thanks

推荐答案

首先,您没有内存泄漏问题。至少现在还没有。



您可能正在使用任务管理器来了解您的应用程序使用了多少内存。错误!任务管理器告诉您.NET CLR应用程序保留了多少,而不是它实际使用了多少。了解.NET CLR内存管理器的工作原理。谷歌的.NET CLR内存管理。 (这就是为什么你认为内存缓慢释放的原因。)



如果你还没有别的东西,请使用PerfMon和.NET内存计数器来查看您的应用程序实际使用了多少。



接下来,就性能而言,您需要查看图像的大小,位深度和图像格式。 BMP是32bpp格式,不使用压缩技术来减少图像的字节数。当您在数据库中创建图像时,您可以将它们调整为应用程序将使用的最大大小,并且可以将它们转换为另一种格式,如PNG,这可以大大减少图像的字节数。
First, you don't have a memory leak problem. At least not yet.

You're probably using Task Manager to get find out how much memory your app is using. WRONG! Task Manager is telling you how much your .NET CLR app has RESERVED for it, not how much it's actually using. Learn how the .NET CLR memory manager works. Google for ".NET CLR memory management". (This is why you think the memory is being freed up slowly.)

If you've got nothing else, use the PerfMon and the .NET Memory counters to see how much your app is actually using.

Next, as for performance, you need to look at the size of your images, their bit depth and the format of the images. BMP is a 32bpp format that uses no compression techniques to reduce the byte count of the image. When you create the images in your database you can resize them to the maximum size your app will ever use and you can convert them to another format, like PNG, which greatly reduces the byte count for an image.

这篇关于Image vs Border vs Rectangle来克服内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆