|
-
Oct 10th, 2002, 10:45 AM
#1
Thread Starter
Registered User
How are objects destroyed in VB6 ?
Hello,
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
-
Oct 11th, 2002, 02:50 AM
#2
You need to look up byval & byref calls for a better explanation, but the general idea is:
- ByRef - you pass the actual recordset variable across to the procedure.
- ByVal - vb makes a virtual copy of the recordset & passes this into the procedure (hance any changes you make don't affect the original recordset).
So if you set a value in one procedure, then pass this value using Byval to a second procedure and make a call to destroy it, you are destroying the actual value itself:
VB Code:
Private Sub form_load()
set rs = new recordset reference created & set
call myProcedure
End Sub
Private Sub myprocedure(byval myrs as adodb.recordset)
msgbox rs!FieldValue
rs.close
set rs = nothing
End sub
Last edited by alex_read; Oct 14th, 2002 at 02:53 AM.
-
Oct 13th, 2002, 03:30 AM
#3
PowerPoster
Alex, you have your Byval and ByRef explanation backwards.
-
Oct 14th, 2002, 02:54 AM
#4
Damn, I always do that. Sorry for any confusion - I've updated the above.
-
Oct 15th, 2002, 12:19 PM
#5
Lively Member
I think you are a little bit confused here.
When you pass object byVal you do not pass a copy of this object, but only a pointer copy
This link will give you explanation.
http://www.vb2themax.com/Item.asp?Pa...Cat=500&ID=278
-
Oct 15th, 2002, 03:08 PM
#6
Frenzied Member
All object variables in VB are pointers to objects. What they really are: function pointers that point to the first element of an array of functions (vtable).
Set object=Nothing may destroy an object - ie., the SCM unmaps the memory used by the object. BUT. It only does this if the number of references to the object (by the thread or process)
goes to zero.
Code:
Dim w as object, x as object
Set w= New ListBox
Set x=w
In this case, Set x= Nothing destroys the object because only ONE version of the object was created. x is a copy of w.
-
Oct 16th, 2002, 01:58 AM
#7
learn something new every day!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|