|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problems with pictureboxes and memory usageme some trouble when it comes to working with a picturebox and memory usage. My company deals with digital imaging, so we are dealing with high resolution images (2500x3300pixels.) The application allows the user to browse through the images in a directory to find the images they need (files listed in a listbox, clicking on the item displays it in a picturebox.) The problem is that memory usage just keeps climbing and climbing as the user browses through the images. The program will start around with about 24MB of usage. But after viewing about a dozen images, it will have doubled to around 50MB. This number will just keep on climbing as more images are viewed. I've tried loading the image two ways 1. picImage.Image = Image.FromFile(filename) and the second way which I saw a post about using to resolve memory leaks 2. Dim _image As Image _image = Image.FromFile(filename) picImage.Image = _image They both end up with the same results. The only way I have found that keeps the memory from skyrocketing is to call GC.Collect() at the end of the function that loads the images, which is supposed to be one of the most evil things you can do in most situations. Anyone have any ideas? I don't want to have to call GC.Collect() since everyone says how horrible it is, but it's the only reliable way I've found to keep the memory down (the machines running the application will be Win98 machines with only 256MB of RAM for a while at least, so I'd like to keep the memory usage down.) Thanks, Jeff Jeff,
Show quoteHide quote "Jeff" <jssig***@woh.rr.com> schrieb im: The memory usage shown in the task manager is not significant. An > I've been working on an application for a while now that has been giving > me some trouble when it comes to working with a picturebox and memory > usage. My company deals with digital imaging, so we are dealing with high > resolution images (2500x3300pixels.) > > The application allows the user to browse through the images in a > directory to find the images they need (files listed in a listbox, > clicking on the item displays it in a picturebox.) The problem is that > memory usage just keeps climbing and climbing as the user browses through > the images. > > The program will start around with about 24MB of usage. But after viewing > about a dozen images, it will have doubled to around 50MB. This number > will just keep on climbing as more images are viewed. application may have a much smaller memory requirement than shown in the task manager because the GC internally "frees" memory and later reuses it. > I've tried loading the image two ways The code is semantically identical, so you won't experience a difference.> 1. > picImage.Image = Image.FromFile(filename) > and the second way which I saw a post about using to resolve memory leaks > 2. > Dim _image As Image > _image = Image.FromFile(filename) > picImage.Image = _image > > They both end up with the same results. > The only way I have found that keeps the memory from skyrocketing is to The GC should run from time to time automatically, so there is no need to > call GC.Collect() at the end of the function that loads the images, which > is supposed to be one of the most evil things you can do in most > situations. explicitly call it in most situations. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> If your code is simply replacing the image in the picturebox and not
explicitly calling Dispose on the images then you'll probably have problems. Try something like: Image i=myPicBox.Image; myPicBox.Image=newimage; i.Dispose(); -- Show quoteHide quoteBob Powell [MVP] Visual C#, System.Drawing Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm All new articles provide code in C# and VB.NET. Subscribe to the RSS feeds provided and never miss a new article. "Jeff" <jssig***@woh.rr.com> wrote in message news:uSox2ChNFHA.3420@tk2msftngp13.phx.gbl... > I've been working on an application for a while now that has been giving > me some trouble when it comes to working with a picturebox and memory > usage. My company deals with digital imaging, so we are dealing with high > resolution images (2500x3300pixels.) > > The application allows the user to browse through the images in a > directory to find the images they need (files listed in a listbox, > clicking on the item displays it in a picturebox.) The problem is that > memory usage just keeps climbing and climbing as the user browses through > the images. > > The program will start around with about 24MB of usage. But after viewing > about a dozen images, it will have doubled to around 50MB. This number > will just keep on climbing as more images are viewed. > > I've tried loading the image two ways > 1. > picImage.Image = Image.FromFile(filename) > and the second way which I saw a post about using to resolve memory leaks > 2. > Dim _image As Image > _image = Image.FromFile(filename) > picImage.Image = _image > > They both end up with the same results. The only way I have found that > keeps the memory from skyrocketing is to call GC.Collect() at the end of > the function that loads the images, which is supposed to be one of the > most evil things you can do in most situations. > > Anyone have any ideas? I don't want to have to call GC.Collect() since > everyone says how horrible it is, but it's the only reliable way I've > found to keep the memory down (the machines running the application will > be Win98 machines with only 256MB of RAM for a while at least, so I'd like > to keep the memory usage down.) > > Thanks, > Jeff Thanks Bob! That did the trick. I had been trying to dispose, but was
getting errors instead. I would have never thought of doing it that way. The memory usage is now the same as when I was using GC.Collect. Perfect timing too, as I just finished the application otherwise. Thanks again. Jeff Bob Powell [MVP] wrote: Show quoteHide quote > If your code is simply replacing the image in the picturebox and not > explicitly calling Dispose on the images then you'll probably have problems. > > Try something like: > > Image i=myPicBox.Image; > myPicBox.Image=newimage; > i.Dispose(); >
activeX doesn't dispose
ImageList issue delete a record from datagrid detect mouse event on node of a treeview unbounded array of objects gets error when instantiating elements Adding the same file to multiple projects. FTP client newbie stupidity: opening one form and closing another How can I loop through all of the messages in the inbox - VB.NET E how to submit a form when enter is pressed |
|||||||||||||||||||||||