Click to See Complete Forum and Search --> : Classes / Objects


Mongoose
January 24th, 2000, 02:44 PM
I have a question about the following code

'globa variable
dim g_rcRecordSet as ADODB.Recordset

'button click
set g_rcRecordSet = getRecordsetFromDatabase()
set g_rcRecordSet = getAnotherRecordsetFromDatabase()

now once i call the getanother function... will that be a memory leak since i didn't set it to nothing before i called the function?

Chris Eastwood
January 24th, 2000, 02:55 PM
It *shouldn't* cause a leak of any kind as long as M$ have implemented the recordset correctly to follow the rules of COM.

I'm not too sure about the ADO Recordset (haven't used them for a while), but you should really make sure that it's closed first before you assign it to another recordset object (just incase).

You can try out the assigning object variables by stepping through a simple class in the IDE, eg:

(Class Module : cThing.cls)

option Explicit
'
private msThing as string
'
private Sub Class_Initialize()
msThing = "Hello" ' breakpoint here
End Sub
'
private Sub Class_Terminate()
msThing = "" ' breakpoint here
End Sub




If you then call this code from a form/anywhere else :


Dim o as cThing
'
set o = new cThing
set o = new cThing




- and step through it - you'll see that cThing get's instantiated twice before one of the instances terminates (which kind-of makes sense if you think about it).


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb