Objects set to nothing

Discussion in 'ASP General' started by Tony, Oct 16, 2003.

  1. Tony

    Tony Guest

    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
     
    Tony, Oct 16, 2003
    #1
    1. Advertising

  2. Tony

    Chris Barber Guest

    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.

    "Tony" <> wrote in message
    news:022701c393b8$96acfa10$...
    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
     
    Chris Barber, Oct 16, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Rodrigues

    Re: Session variables set to nothing??

    Mark Rodrigues, Oct 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    391
    Mark Rodrigues
    Oct 29, 2003
  2. Thanks
    Replies:
    2
    Views:
    1,702
    Thanks
    Feb 8, 2004
  3. Jie
    Replies:
    1
    Views:
    657
  4. Jeff Carver
    Replies:
    3
    Views:
    451
    Jeff Carver
    Aug 25, 2004
  5. Devin Jeanpierre
    Replies:
    2
    Views:
    492
    Devin Jeanpierre
    Feb 14, 2012
Loading...

Share This Page