For how long will an ASP.NET process hold resources?

L

Lau Lei Cheong

Hello everyone,

I was believing that the life of ASP.NET objects will end as soon as the
origionating Page object transmitted the response stream and frees, even if
you haven't explicitly free the objects, but now I'm not quite sure.

It happened to me that I have a ASP.NET page that'll read images from
the server to generate another image. For quick hand I've used the code like
this in order to "save" one variable declaration. (The code resides in
another object the Page creates.)

g.DrawImage(new System.Drawing.Bitmap(ImgFilePath1), 0, 0, w1, h1);

And soon I found the w3wp.exe continuously locks any files opened this
way. Now I've changed the program to the following to get rid of the
problem.

pic1 = new System.Drawing.Bitmap(ImgFilePath1);
g.DrawImage(pic1, 0, 0, w1, h1);
pic1.Dispose();

Now I wonders if file handles will not be freed, will memory or other
system resources be hold - perhep until the global GC process finally
collects them?

Thanks for any inputs.

Regards,
Lau Lei Cheong
 
G

garethdjames

In my experience when ever working with any kind of stream and using
any kind of COM object it is best to explicitly close or dispose of the
objects.

We observed behavior of a message queue that did not release resources
until dispose was called, this was caused by (if I remember correctly)
the .Net message queue holding onto COM resources
 
K

Kevin Spencer

As a general rule, anything that implements IDisposable should ALWAYS be
disposed. In the case of file IO, it should be closed and disposed as
quickly as possible.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top