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
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
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