473,657 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PictureBox image + Garbage cleanup problem . .. Please help

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.pi ctureBox1.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
3 3341
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.h r...
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.pi ctureBox1.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
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
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.Colle ct();
System.GC.WaitF orPendingFinali zers();

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
31511
by: Pavan Arise | last post by:
Dear all.. I have a picturebox filled on a form. The picturebox has some graphics displayed on it.I was trying to save the picturebox, but continuesly failed to do so. I am clueless of why it is happening. I tried to save the image of the form & also the picturebox, but always, i see a blank file saved. Is there a way to save whatever is displayed on the picturebox, to a file?? Thanks for any suggestions and help. Regards,
15
1811
by: Jose Michael Meo R. Barrido | last post by:
Hi! Can u please tech me a way to know if the image in the picturebox has changed? what event should i catch the chage?
4
28174
by: Ed Landau | last post by:
In VB6.0, I can put an image on a form and assign it's .picture property at run-time. In VBA (within MS Access), when I put down an image control on a form, it asks me for the source to the image (at design-time). Why? Why can't I find PictureBox in VBA within MS Access? And most importantly...why can't I put either in a Report within MS Access? What I really want is to be able to display pictures in an MS Access report (pictures...
2
12976
by: Sean | last post by:
Hello all, I have an application that is using some picture box controls that are being used to preview jpg files. The jpg files are created on the fly and will be overwritten when needed. The issue I'm having is that when I release the picturebox resources, they still seem to be hanging on at the OS level because I can't delete the file. Here's a code snippet of what I'm doing:
5
2419
by: Mike Dole | last post by:
When I am updating a picturebox with an image (extracted) from an access database I keep getting a "The process cannot access the file "c:\foto1.jpg because it is being used by another process" this only happens the second time I run it, the first time it works out fine.. I've tried things like MyPicBox.dispose MyPicBox = nothing etc,etc
3
6365
by: Ger | last post by:
I have a form with a panel (Panel1) in which I dynamically create picturebox controls. Works like a dream with static pictures, but not when the picturebox.image is an animated gif. GDI+ throws the following error in this case: "An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in system.windows.forms.dll Additional information: A generic error occurred in GDI+."
18
2195
by: Larry Herbinaux | last post by:
I'm having issues with garbage collection with my long-standing service process. If you could review and point me in the right direction it would be of great help. If there are any helpful documents that you could point me to help me control the GC, then that would be great also. The .Net GC does not cleanup memory of our service process unless it is forced to by another process that hogs memory. · GC Algorithm - This is an issue...
1
1419
by: The Confessor | last post by:
(ellipses in place of code sections which do not deviate from defaults) Private Sub Form_Main_Load(...) Handles MyBase.Load For A = 0 To 16 For B = 0 To 14 PictureBox_MapEditor_Map.CreateGraphics.DrawImage (System.Drawing.Image.FromFile("C:\The RPG Project\Test 2.bmp"), A * 40, B * 40) Next Next
5
5375
by: AWW | last post by:
XP VB 2005 running an example from help that creates a picturebox in code - the picturebox is not created. If I comment out the "Dim Box as New PictureBox" and create it in Design mode - the example works. I have tried Show, Enabled, Visible, and even BackColor. Why does a help example not work? and why does Design creation work? Thanks - I hope.
0
8402
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5633
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4164
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.