Jorgie wrote:
Even though the Image object goes out of scope right after I finish with it, if I don't call the images dispose function my memory use grows to 128MB or higher after running for 24hours or more. Once I started using the image objects dispose function, the application never uses more than 4BM.
There's a difference between managed
objects and managed
memory. Even though Image is a managed class, it holds unmanaged resources (in this case, a handle to a GDI object where the bitmap is actually mapped. You can see this by opening
Reflector and looking at the Dispose(Boolean) and FromFile(string) methods on the Image object. Lots of unmanaged memory mapping going on.
Same thing goes for Stream objects - the object itself is managed, but it holds unmanaged resources (file handles and locks, in this case).
In general principle, you can assume that if a framework class implements IDisposable, it probably holds some unmanaged resource and you SHOULD call Dispose() if you know you're done with it. When in doubt - Reflector.
