Windows Develop Bookmark and Share   
 index > Windows Forms General > OutOfMemory exception when loading large images
 

OutOfMemory exception when loading large images

I have a problem when loading some pretty large images. The images are ~700mb uncompressed, and the two first times I load an image, everything works fine.

Each time I'm done with an image, I force a Garbage Collection using GC.Collect() and I can see in the task manager that resources are actually being released.

The weird thing is that when I load the third image to process (it's the same function called from a loop), I always get an OutOfMemory exception. (note: the third image is not always the same image file)

Not even closing and disposing the worker thread and restarting it wil cut it. I have to exit the whole application to make it run again without the memory exception.

Any ideas on what I can do to prevent this is highly appreciated.

(The best thing was probably to be able to read pixels in the the tiff file by directly accessing the file, instead of loading the whole file into memory.)
MigrationUser 1  Saturday, July 17, 2004 2:12 PM
You really need to investigate streaming IO just as you mentioned. You'll probably have to write your own classes to do this or investigate a third party product that has this feature.

There may be some residual memory consumption left over and you are simply topping out after 3 images because of the residuals left behind. What I would recommend is making sure you follow the Dispose pattern and Dispose of the image references, and make sure to call WaitForPendingFinalizers() to ensure the GC is 100% complete.

What you may be seeing is that the memory isn't being collected immediately (you can see it in the Task Manager, but that doesn't mean it is collected when you start the next load).
MigrationUser 1  Sunday, July 18, 2004 3:25 AM

You can use google to search for other answers

Custom Search

More Threads

• Reposition control in DataGridView instead of a form
• How to skin Windows Forms?
• TextBox, KeyPress event, F2 Key
• Passing Data between EXEs
• right-click event
• Drag & Drop Rich Text Boxes
• Managing a disabled control
• treeview click event
• Selecting empty values from Database error
• 'global' key events ?