473,497 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problems with pictureboxes and memory usage

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
Nov 21 '05 #1
3 5420
Jeff,

"Jeff" <js******@woh.rr.com> schrieb im:
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.
The memory usage shown in the task manager is not significant. An
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
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 code is semantically identical, so you won't experience a difference.
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.


The GC should run from time to time automatically, so there is no need to
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/>

Nov 21 '05 #2
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();

--
Bob 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" <js******@woh.rr.com> wrote in message
news:uS**************@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

Nov 21 '05 #3
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:
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();

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6057
by: Justice | last post by:
Currently I'm doing some experimenting with the XMLHTTP object in Javascript. Now, the XMLHttp object is asynchronous (at least in this case), and the following code causes a significant memory...
6
3228
by: Tom | last post by:
We have a VERY simple .NET C# Form Application, that has about a 23MB Memory Footprint. It starts a window runs a process and does a regular expression. I have done a GC.Collect to make sure that,...
3
4110
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
16
2368
by: JCauble | last post by:
We have a large Asp.net application that is currently crashing our production servers. What we are seeing is the aspnet_wp eat up a bunch of memory and then stop unexpectedly. Does not recycle. ...
7
8095
by: Scott Mackay | last post by:
Hi, I'm using visual studio dotnet 2002 programming in vb can anyone tell me how I can handle the mousedown event for pictureboxes I create dynamically at runtime? I've tried setting the...
21
2905
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
5
1516
by: hamishd | last post by:
Hello, In my application I create some large vectors to hold data. For example: std::vector<DataItemClass*MyData; DataItemClass * DataItem; for(i=0;i<SomeLargeLimit;i++){ DataItem = new...
409
10718
by: jacob navia | last post by:
I am trying to compile as much code in 64 bit mode as possible to test the 64 bit version of lcc-win. The problem appears now that size_t is now 64 bits. Fine. It has to be since there are...
1
2020
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after...
0
7120
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6878
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.