CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2000
    Location
    Tallahassee, FL
    Posts
    121

    Classes / Objects


    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?


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Classes / Objects

    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

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