High Memory Usage

Jan 14, 2009 at 10:26 PM
Edited Jan 14, 2009 at 10:38 PM
This is a beautiful application. Unfortunately is good only to show a couple of pictures.
I tested the Slide.Show with about 300 pictures (180MB in total) in one album.
It stops responding for a while then it works intermittently. 
Windows Task Manager indicates that  IExplorer.exe instance with the Slide.Show uses more than 1GB from the available memory.
 Does anyone else have these problems?
Jan 15, 2009 at 7:24 AM

what size are your thumbnails? I have tried this with 300 images in one album with small thumbs (4 kB) - the memory usage of IE is about 81 MB. When using the images itself as thumbs the memory usage increases like you described because all thumbs are loaded in the SlidePreview.

Jan 15, 2009 at 10:01 AM
Yes, I used the images itself as thumbs. It's easier. 
Jan 16, 2009 at 7:46 AM
Edited Jan 16, 2009 at 7:47 AM

hers the VB-code for a little ThumbsGenerator - execute it in the directory with the JPEGs and it creates a 120px thumb file with the name *_t.jpg. Then you can replace ".jpg" />\n" with "_t.jpg" />\n" in your Data.xml.


Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging

Module Module1

    Sub Main()
            Dim images = Directory.GetFileSystemEntries(Environment.CurrentDirectory, "*.jpg")
            For Each image In images
                Dim thumbImage As String = Path.GetDirectoryName(image) & "\" & Path.GetFileNameWithoutExtension(image) & "_t" & Path.GetExtension(image)
                If Not File.Exists(thumbImage) Then
                    Dim tempImage As String = Path.GetDirectoryName(image) & "\" & Path.GetFileNameWithoutExtension(image) & "_temp" & Path.GetExtension(image)
                    File.Copy(image, tempImage)
                    ResizeImage(tempImage, thumbImage, 120)
                End If
        Catch ex As Exception
        End Try
    End Sub

    Private Sub ResizeImage(ByVal inputFileName As String, ByVal outputFileName As String, ByVal maxSize As Integer)
        Using fs As New FileStream(inputFileName, FileMode.Open)
            Using inputImage = Image.FromStream(fs)
                Dim currentSize = Math.Max(inputImage.Width, inputImage.Height)
                Dim newWidth = inputImage.Width
                Dim newHeight = inputImage.Height
                If currentSize > maxSize Then
                    Dim sizeFactor = maxSize / CDbl(currentSize)
                    newWidth = CInt(sizeFactor * newWidth)
                    newHeight = CInt(sizeFactor * newHeight)
                End If

                Dim ici As ImageCodecInfo = GetCodec("image/jpeg")
                Dim ep As EncoderParameters = New EncoderParameters(1)
                'Set Quality Parameter
                ep.Param(0) = New EncoderParameter(Encoder.Quality, 20)
                'Save to a Memory Stream
                Using ms As New System.IO.MemoryStream
                    inputImage.Save(ms, ici, ep)
                    Using newImage1 = Image.FromStream(ms)
                        Using newImage2 As New Bitmap(newImage1, newWidth, newHeight)
                            newImage2.Save(outputFileName, inputImage.RawFormat)
                        End Using
                    End Using
                End Using
            End Using
        End Using

    End Sub



    Private Function GetCodec(ByVal type As String) As ImageCodecInfo
        Dim mime As String = SetMime(type)
        If mime Is Nothing Then Return Nothing
        For Each codec As ImageCodecInfo In ImageCodecInfo.GetImageEncoders
            If (codec.MimeType = mime) Then
                Return codec
            End If
        Return Nothing
    End Function

    Public Function SetMime(ByVal imagetype As String) As String
        Select Case imagetype.ToLower.Trim
            Case "jpg", "jpeg", "image/jpg", "image/jpeg"
                Return "image/jpeg"
            Case "bmp", "image/bmp"
                Return "image/bmp"
            Case "gif", "image/gif"
                Return "image/gif"
            Case "tif", "tiff", "image/tif", "image/tiff"
                Return "image/tiff"
            Case "png", "image/png"
                Return "image/png"
            Case Else
                Return Nothing
        End Select
    End Function

End Module

Jan 16, 2009 at 10:30 AM
Thank you,
I did test the Slide.Show with small thumbs. It works better.
Mar 19, 2009 at 6:57 PM
I am using thumbnails also and I am still seeing 100+ MB for iexplore.exe in the Task Manager when it is looping through the albums.  I have 4 albums with the following number of pictures in each: 10, 40, 28, 12.  The full image is 1024x768 resolution and the thumbnail is 5-6K each.  All of the images are .jpgs.  Also, I would expect the memory to decrease if I went back to an album that I already viewed.  The memory never goes down.

This works perfectly as I need it - I just wish there was something to do about improving the client side performance.   I'm afraid to add any more albums as it seems to get slower and slower with each albums.

Anyone got any advice on how to speed it up more or is there something I am missing?

Jun 20, 2009 at 9:02 PM

Slide.Show 2 has a definate and huge memory leak that could cause it to consume vast quantities of memory, particularly with albums with lots of photos.  This was logged as an issue #2701:  Memory Leak

I have posted details about how to fix the issue here:  Memory Leak "resolved".