Objects set to nothing

T

Tony

Hi,
anyone have better information on IIS 5.0 memory behaviour
on setting objects to nothing?

Connections and recordsets of course should be set to
nothing, but should for example XMLNode object be set to
nothing?

Thanks, Tony
 
C

Chris Barber

Setting to Nothing is a bit of a misnomer in that as soon as the current ASP
page goes out of scope (eg. has completed processing) then all objects are
contacted and told to destroy themselves anyway.
It is true that in a stateful environment such as a classic VB application
that not setting global and module level objects to Nothing can have an
adverse effect on memory usage since those objects may remain in scope (and
thus in memory) for a lot longer than anticipated.
I have seen a classic example of this in my own application working with a
mail archive (1000+ mails). I enumerated them to a collection and held a
mail COM object for each. I forgot to set the object to nothing as I was
running through the collection collecting the header information resulting
in a dramatic rise in memory to over 500Mb. When I realised the mistake and
then set each mail object to nothing after I had finished with it then the
memory remained static at < 2Mb.
However, in ASP, only application and session objects [not strictly true -
see later] persist beyond the scope of a single ASP page being processed and
so the issue of 'managing' the objects lifetime becomes moot....as the page
completes then all objects go out of scope automatically.
There is a situation in which setting to Nothing must be done [in fact you
need to call the relevant .Quit method first] ... when working with
ActivexEXE Servers. These objects create out of process copies of certain
public classes that can be made to persist outside the scope of a page. This
is due to the fact that the class object is referenced by the ActivexEXE
Server, not the ASP page. A good example is instantiating an instance of
Excel in an ASP page and not calling .Quit on it before the page completes
..... Excel will remain active and in memory but divorced from all efforts to
communicate with it. Excel is in fact an ActivexEXE Server as is Word, etc.
That's one of the main issues with trying to use Excel server-side in a web
environment, it has the capability to eat up all the server memory if you
get it wrong.

My apologies if I get anything slightly mis-quoted, it's a bit of a
contentious subject with IIS and I'm not an MVP (although I'd like to be at
some point if I can ever find the time to do the exams etc.).

Hope this helps,

Chris.

Hi,
anyone have better information on IIS 5.0 memory behaviour
on setting objects to nothing?

Connections and recordsets of course should be set to
nothing, but should for example XMLNode object be set to
nothing?

Thanks, Tony
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top