CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Object chaining

  1. #1
    Join Date
    May 1999
    Posts
    318

    Object chaining

    How could i delete an object from memory when the object has been created with New keyword.


    Dim obj1 as MyClass
    set obj1=new MyClass
    ' How to delete obj1 from memory ???




    If i affect Nothing to obj1 will be the object removed from memory (like a Java garbage collector ) ?

    thanx





  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Object chaining

    Set obj1 = Nothing
    removes the object from memory (under normal circumstances)


  3. #3
    Join Date
    May 1999
    Posts
    318

    Re: Object chaining

    So if i understand and i have several object variables that point to the same object i must free all variables

    ie :

    Dim obj1,obj2,obj3 as myclass

    set obj1=new myclass
    set obj2=obj1
    set obj3=obj1

    ' now obj1,obj2 and obj3 point to the same memory object

    set obj1=nothing
    set obj2=nothing
    ' ONLY the last next line frees the object ????
    set obj3=nothing








  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: Object chaining

    if you want to find out the truth, write a Class_Terminate method ("desctructor") in myclass and check when that method is called. That will tell you the truth about object destruction.


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

Featured