.NETGURU
OutOfMemory exception when loading large images
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.performance.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

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

/Morten Nielsen
Email: http://www.iter.dk/contact.aspx

Reply to this message...
 
    
Morten Nielsen
I'm sorry, it's obviously not ALWAYS the third image. Sometimes it happens
later in the loop.
I noticed a thing when processing the image before the image that creates an
OutOfMemory exception when loaded. The physical memory used is much larger
(the virtuel memory used is the same) than with the previous images. The
Garbage collection does clean this up just before the exception, but maybe
it gives a hint on what wrongs.

Again... it doesn't have anything to do with the actual image that is being
loaded. It loads just fine if it is processed a little earlier in the loop.

After garbage collecting the memory usage is always 12mb physical and 52mb
virtual. After loading the image (when it is succesful), the usage is 54mb
physical and 757mb virtual.

/Morten

Reply to this message...
 
    
Michael Pearson
Are you calling Dispose() on your image object?

Michael

"Morten Nielsen" <Click here to reveal e-mail address> wrote in message
news:40f97228$0$23881$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Morten Nielsen
> Are you calling Dispose() on your image object?
Yup.

Forcing Garbage collection seems to help a bit (it doesn't happen just as
often).

/Morten

Reply to this message...
 
    
fd123456
Hi Morten,

Not sure at all it works, but it might help... Try :

GC.WaitForPendingFinalizers();

....right after your GC.Collect(). It suspends execution until all
finalizers have done their magic. If you have for instance 512 MB of
RAM, then your total memory (including virtual memory) is around 1500
MB, which means that two of your images cannot possibly be held in
memory at the same time (taking into account the 200MB+ that a
"normal" system occupies). Maybe waiting for the GC to have released
the memory could solve your problem.

HTH.

Michel

"Morten Nielsen" <Click here to reveal e-mail address> wrote in message news:<4102676d$0$66474$Click here to reveal e-mail address>...
[Original message clipped]

Reply to this message...
 
    
David Notario [MSFT] (VIP)
Are you just allocating a big 700 Mb chunk? If yes, you are going to have
problems finding 700 contiguous Mb in virtual address space, you may want to
split the image into more manageable chunks

Have you tried Allocation profiler? Maybe there are unexpected referenced
objects

--
David Notario
Software Design Engineer, CLR JIT Compiler
http://devdiary.xplsv.com

"Morten Nielsen" <Click here to reveal e-mail address> wrote in message
news:40f96b78$0$23869$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.GC




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification