Re: Cycling between images increases memory usage

From: Bob Powell [MVP] (bob_at__spamkiller_bobpowell.net)
Date: 05/09/04


Date: Sun, 9 May 2004 13:23:50 +0200

Ahh, I see.

I will run a test myself to see what the effect is. Maybe PictureBox has a
leak. It's my least favourite control and the easiest to write a
replacement for so that's an option.

I'm glad you enjoy my site.

-- 
Bob Powell [MVP]
Visual C#, System.Drawing
Image transition effects, automatic persistent configuration and
design time mouse operations all in April's issue of Well Formed
http://www.bobpowell.net/wellformed.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedId=41
"Scytrax" <anonymous@discussions.microsoft.com> wrote in message
news:9D27A085-BA98-4298-A711-20ED45AF0F25@microsoft.com...
> Hi Bob.
>
> I read your faq recently and realized the importance of disposing images.
That handled another problem I was having in the same application. Thanks.
>
> However, when cycling images in the picture box, I cannot dispose of the
image because I keep looping through the images and so I need all images to
be displayed more than once.
>
> I do  something like the following (pseudo code):
>
> int counter = 0;
> Image images[] = new Image[5];
> images[0] = Image.FromFile("image1");
> images[1] = Image.FromFile("image1");
> images[2] = Image.FromFile("image1");
> images[3] = Image.FromFile("image1");
> images[4] = Image.FromFile("image1");
> this.Timer1.Start();
>
> onTimerTick:
>
> this.PictureBox1.Image = this.images[counter++];
> if(counter == this.images.Length)counter = 0;
>
> In theory, this should not cause any memory problems, right?
>
> I have been testing my program again during the night and after running
app. 6 hours, I only had an increase of about 200K. So maybe I don't have a
problem anymore. However, I would still like a confirmation that the general
procedure as described above should not cause any memory problems.
>
> Thanks for being a great help to your fellow coders, Bob!
>
> Anders


Relevant Pages

  • Re: Event Matchmaker updated
    ... > critique without giving constructive feedback. ... all the thumbnail images are full size images ... being resized by the browser. ... - The FAQ pages don't look anything like any FAQ I've ever seen, ...
    (rec.juggling)
  • Re: Animated GIF as background
    ... My application requires a moving images over other another images. ... If I slip a picture box under my moving picturebox, I wind up seeing all the ... simplicity of having an animated GIF as the base forms image. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Advice about Master documents
    ... Microsoft's Legal Users' Guide) http://addbalance.com/usersguide ... See also the MVP FAQ: http://www.mvps.org/word which is awesome! ... >> necessarily mean the images have been corrupted, ...
    (microsoft.public.word.formatting.longdocs)
  • Memory problem with images
    ... I'm developing a ppc application that receives images from a url and ... periodically displays them in a picturebox (I use a timer control). ... private sub tickhandles myTimer.tick ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Resize Image for ListView
    ... I like the idea of a PictureBox. ... I know we have to add the images to ImageList before using them ... on ListView but even with ImageList, there seems to be no way to resize ...
    (microsoft.public.vb.general.discussion)