By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,763 Members | 1,641 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,763 IT Pros & Developers. It's quick & easy.

PictureBox image + Garbage cleanup problem . .. Please help

P: n/a
Hi all!

I've made a little app that creates thumbnails and if user clicks on it, it
displays the original picture in the picturebox on a panel control.
In a thumbnail mouse down event I'm using static method
Image.FromFile(string path).Something like this:

this.mainApp.pictureBox1.Image = Image.FromFile( imagePath )

Well ... the problem starts when loading a image 3200x2400x24bit which is
about 1.7 MB on disk, it takes approximately 25MB RAM when loaded??? Why ???
The problem gets worse if user clicks on the multiple thumbs(every image
thumb represents is 3200x2400) in a short amount of time.
As user clicks on each thumb, the memory usage is pilling up. For every
1.7MB picture for about 25MB. Usually GC starts cleanup near 1GB when it
hits the ceiling of my system of 1GB.
Now why GC cleans up the memory so infrequent and waits till all resources
are nearly full?
Am I missing something here. I can't believe I'm stuck on somethig stupid
like this.

Please help me, I'm near breakdown!

Thanks in advance! and Marry Christmas all!

My specs:
Athlon Barton 2.5
1 GB RAM
Win2k sp4
DOT Net 2beta

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.806 / Virus Database: 548 - Release Date: 05.12.2004
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You have to remember that images are often stored on disk in a compressed
format. JPEG compression is very efficient, if lossy, and enables quite
significant savings in file-size over real-size of an image.

When calculating the real memory requrements of an image you need to
consider the equation h*w*d/8 which is height times width times bit-depth
divided by 8.

An image you suggest of 3200*2400*24 bits requires over 23 megabytes to
store in its uncompressed raster form. No surprise then that your app
requires 25 megs.

--
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.

"CroDude" <di***********@zg.htnet.hr> wrote in message
news:cq**********@news1.xnet.hr...
Hi all!

I've made a little app that creates thumbnails and if user clicks on it, it displays the original picture in the picturebox on a panel control.
In a thumbnail mouse down event I'm using static method
Image.FromFile(string path).Something like this:

this.mainApp.pictureBox1.Image = Image.FromFile( imagePath )

Well ... the problem starts when loading a image 3200x2400x24bit which is
about 1.7 MB on disk, it takes approximately 25MB RAM when loaded??? Why ??? The problem gets worse if user clicks on the multiple thumbs(every image
thumb represents is 3200x2400) in a short amount of time.
As user clicks on each thumb, the memory usage is pilling up. For every
1.7MB picture for about 25MB. Usually GC starts cleanup near 1GB when it
hits the ceiling of my system of 1GB.
Now why GC cleans up the memory so infrequent and waits till all resources
are nearly full?
Am I missing something here. I can't believe I'm stuck on somethig stupid
like this.

Please help me, I'm near breakdown!

Thanks in advance! and Marry Christmas all!

My specs:
Athlon Barton 2.5
1 GB RAM
Win2k sp4
DOT Net 2beta

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.806 / Virus Database: 548 - Release Date: 05.12.2004

Nov 16 '05 #2

P: n/a
Hey,
Just a note, take your 1.7 Mb image file and save it as .BMP file.
You will see, that it takes around 20-25 Mb on disk as well.
If JPEG takes 1.7Mb, it should be either awesome quality picture,
or just wase of space (which is probably not the case).

Then compress your BMP with any archiver (ZIP, RAR, ARJ, ACE, CAB, etc)
ZIP or RAR are perhaps the most popular and then look at the filesize.
It should be under 3 megs. Most probably even close to your 1.7 Mb.

So, no wonder, why it takes 25 megs in memory, and to fight that,
you can call garbage collector manually somehow.
I never had to use it, so just play with subpackages of "System."
Or just ask someone else.

AFAIK, (please correct me if I am wrong) GC does the job only when it
"needs" to be done, i.e. if you have half-gig ram still available AND
the CPU is "busy" with some other processes, GC will not start the work,
it will just use the remaining memory.
As soon as it is not enough, GC priority gets higher, and it may even
suspend your program if necessary, to clean the memory.

Hope that helps.

On Sat, 18 Dec 2004 23:46:57 +0100, CroDude <di***********@zg.htnet.hr>
wrote:
Hi all!

I've made a little app that creates thumbnails and if user clicks on it,
it
displays the original picture in the picturebox on a panel control.
In a thumbnail mouse down event I'm using static method
Image.FromFile(string path).Something like this:
..................

--
Regards,
Nurchi BECHED
Nov 16 '05 #3

P: n/a
Thanks for a reply guys!

I've solved the problem and nocked myself a few times for a stupidity
how a jpeg could eat 25MB. Heh ... didn't think at all when posted this
question.
Anyway, memory filling is solved too by calling this after loading an image
to the picBox:

System.GC.Collect();
System.GC.WaitForPendingFinalizers();

Everything works now well ... memory is freeing fine and in a short amount
of time after each image load.
It seems that garbage collector is really slow when working with large
objects, and this method forces GC to go in a trash sweep.

Thanks again!

D ;)

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.806 / Virus Database: 548 - Release Date: 05.12.2004
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.