Results 1 to 7 of 7

Thread: How are objects destroyed in VB6?

  1. #1

    Thread Starter
    Registered User
    Join Date
    Sep 2002
    Posts
    14

    How are objects destroyed in VB6?

    Posed this one also in COM\ActiveX forum, sorry about this...
    Anyone ideas about this one ?

    I have a main app and two classes. The first class gets an ADO recordset from an Access2000 DB. The second class generates
    a csv file from an ADO recordset.

    So my main app asks class1 for a recordset and feeds it into
    class2 which is working fine.

    I am just wondering if the recordset object is being properly destroyed because it first gets instantiated in class 1 and then
    passed by reference all over the project (sometimes using "local" references to the same recordset).

    I saw in VB6 help that if you have multiple references to 1 object, the object gets released if you set the last ref. to nothing.

    OK; but what about passing references ??
    Does anyone have a clear explanation for this ?

    THANKS,
    Jukke

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    If you are passing it ByRef, setting it to nothing would destroy the object for teh whole project, unless you instantiate it again.

  3. #3

    Thread Starter
    Registered User
    Join Date
    Sep 2002
    Posts
    14
    So for example :

    In Class1 :

    Public function GetData() as ADO.RecordSet
    ...
    GetData = ...

    End Function

    In Main :

    Public sub Main()

    Class2.Dosomething(Class1.GetData)

    End Sub

    In Class 2 :

    Public sub Dosomething (rst as ADO.RecordSet)

    ...
    Set rst = nothing

    End sub

    So this means that the rst object gets destroyed in Class 2 upon set to nothing ?

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    I am not sure, but is the function return by value ByRef or ByVal. If its ByVal, it is not getting destroyed, but if its ByRef, it is getting destroyed.

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by amitabh
    I am not sure, but is the function return by value ByRef or ByVal. If its ByVal, it is not getting destroyed, but if its ByRef, it is getting destroyed.
    well by default it is byref if you don't specify... so by your example and from what amitabh said about destroying objects... these objects would be destroyed...


    but i personally like to use a hammer to destroy mine

  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    I am not so sure. The functions return value can be ByRef beacuse it is always assigned to another variable. Okay I will just test it out.

  7. #7
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Sorry, it is ByRef. I just got confused.

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