Results 1 to 4 of 4

Thread: setting objects to Nothing

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2001
    Posts
    33

    setting objects to Nothing

    hi

    i am creating an new object every time and then at the end of
    what i am doing i then set it to nothing


    set obj = new COMobj

    set obj = nothing

    but this seems to be leaking / increasing the memory
    does this nothing statement actually work - does it destroy
    the obj or is there another way of doing this


    thanks
    Louby

  2. #2
    gaffa
    Guest
    You're doing it right.

    The question is, does the object that is being set to nothing do it's own memory cleaning? ie: when the obj_Terminate event fires, is it cleanijng up any objects that it might be holding?

    - gaffa

  3. #3
    jim mcnamara
    Guest
    For example -
    Unless you're at sp5 in VB 6.0 the MSChart control leaks memory like a sieve.

    The answer depends on what object you're referencing, not that you personally are writing poor code.


  4. #4
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    I guess I have two comments. First, when you set an object to nothing, memory and system resources are not immediately released. The reason is that VB does a lot of garbage collection that you, the programmer, do not see, and sometimes it just takes VB a while to clean up the object resources. Second, setting an object to nothing doesn't release all system resources until the variable falls out of scope. So if your object is a global variable, even after it has been set to nothing, the variable will still retain some resources.

    Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width