5 Replies - 1552 Views - Last Post: 07 July 2011 - 09:13 AM Rate Topic: -----

#1 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 979
  • Joined: 09-May 09

Dispose of images everytime?

Posted 06 July 2011 - 03:12 PM

Hi guys, im loading images into 2 picturebox controls

My app works as it should but i need to know when i should dispose of the images or does the garbage collector do it for me?

on a user click the images change, i think that my app will become resource hungry and cause the app to bomb out at some point.

So do i use Picturebox1.dispose() each time new images are loaded into the pictureboxs to free up the image from memory?

Kevin

Is This A Good Question/Topic? 0
  • +

Replies To: Dispose of images everytime?

#2 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1065
  • View blog
  • Posts: 4,170
  • Joined: 02-July 08

Re: Dispose of images everytime?

Posted 06 July 2011 - 03:25 PM

picturebox.dispose disposes the control not the image. So how you are creating/using the images? Most likely you don't need to worry about it.
Was This Post Helpful? 0
  • +
  • -

#3 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 979
  • Joined: 09-May 09

Re: Dispose of images everytime?

Posted 06 July 2011 - 04:02 PM

yeah i have just realised that. I inserted 1 as a trial and noticed the control was missing.

I am adding the image to the control from a location on my hard drive.

i then just change the path for the image to be displayed.

I know the image is being held in memory because i have tried deleting it after i changed the pic in the app and its denied.

Kevin
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1065
  • View blog
  • Posts: 4,170
  • Joined: 02-July 08

Re: Dispose of images everytime?

Posted 06 July 2011 - 07:33 PM

Ok, show me the code you use. If you make a Bitmap then yes call it's dispose method.

Dim bmp As New Bitmap(...)
...
bmp.Dispose()

Was This Post Helpful? 1
  • +
  • -

#5 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 979
  • Joined: 09-May 09

Re: Dispose of images everytime?

Posted 07 July 2011 - 08:30 AM

here is a sample of code im using

Sub findImages(ByVal imageFilePath)

        Try
            ' try and load movie poster from file 
            Dim posterPath = imageFilePath + "\frontCover.jpg"
            Form1.frontCoverPicturebox.Image = Image.FromFile(posterPath)
        Catch
            'If poster is unavailable load unavailable image
            Form1.frontCoverPicturebox.Image = My.Resources.noPosterImage
        End Try

        '   Same as above
        Try
            Dim backdropPath = imageFilePath + "\backdrop.jpg"
            Form1.backdropPicturebox.Image = Image.FromFile(backdropPath)
        Catch ex As Exception
            Form1.backdropPicturebox.Image = My.Resources.noBackdropImage
        End Try

    End Sub



when a user clicks on a movie name in a listview i display the cover and backdrop.
the files are both .jpg, im assuming the images are stored in memory. This example is for 2 images but i have a cover view display where i display 21 images at one time then the user clicks an arrow to load the next 21 images.

i dont want each 21 images to be held in memory because if i have a large collection (200+ movies) then the memory usage of the pc will be high and cause the computer to slow down.
Was This Post Helpful? 0
  • +
  • -

#6 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1065
  • View blog
  • Posts: 4,170
  • Joined: 02-July 08

Re: Dispose of images everytime?

Posted 07 July 2011 - 09:13 AM

If it's not releasing them - which I would think it would have. Set the Image property to nothing before setting the new one. Are you watching the process in the task manager? You can see if by adding the footprint keeps growing other wise it would stay relative size depending on other things your app is doing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1