Checking for memory leaks (open objects) after app is closed 
Author Message
 Checking for memory leaks (open objects) after app is closed

RE: VB 6

I am developing a VB app and have what might appear to be a simple
question with a possibly complexa answer.

In my app, I am setting my recordsets = "nothing" when I close the app,
but I would like to know if, just prior to closing the app, (on the
click event of the "CloseApp" button) if there is a way to check to see
what objects (ie. recordsets, etc) have not been closed and are stiil
open at the close of the app.

Does anyone out there have some sample code that can trap and list what
object or variables have not been closed when an app terminates?

I want to make sure that when my app closes on the users machine, that
they get back all of their memory my app used.

--
Thanks,

RLN

Sent via Deja.com
http://www.*-*-*.com/



Mon, 07 Jul 2003 00:15:30 GMT  
 Checking for memory leaks (open objects) after app is closed
Unfortunately there is no easy way to check all your objects for a Nothing
state.  To do so would require public access of all the recordsets
throughout your application, which is poor programming practice.  It is just
best that you remember to set you recordsets or any objects to Nothing when
you are done with them.  Also make sure you have an error handle in every
subroutine using an object and remember to destroy the object there also...

Example:

Public Function getRecord() As String

    Dim objDbRs As ADODB.Recordset

    On Error GoTo ErrorHandle

    Set objDbRs = New ADODB.Recordset

    With objDbRs

        Set .ActiveConnection = gobjMyConnection
        .Open "select txtRecordValue from tblSample"

        If .RecordCount > 0 Then
            getRecord = objDbRs!txtRecordValue
        Else
            getRecord = vbNullString
        End If

        .Close

    End With

    Set objDbRs = Nothing

    Exit Function
ErrorHandle:
    'If an error occurs...  Destroy the Recordset and return a null
    Set objDbRs = Nothing
    getRecord = vbNullString

End Function


Quote:
> RE: VB 6

> I am developing a VB app and have what might appear to be a simple
> question with a possibly complexa answer.

> In my app, I am setting my recordsets = "nothing" when I close the app,
> but I would like to know if, just prior to closing the app, (on the
> click event of the "CloseApp" button) if there is a way to check to see
> what objects (ie. recordsets, etc) have not been closed and are stiil
> open at the close of the app.

> Does anyone out there have some sample code that can trap and list what
> object or variables have not been closed when an app terminates?

> I want to make sure that when my app closes on the users machine, that
> they get back all of their memory my app used.

> --
> Thanks,

> RLN

> Sent via Deja.com
> http://www.deja.com/



Mon, 07 Jul 2003 09:57:30 GMT  
 Checking for memory leaks (open objects) after app is closed
Thanks for your reply, Robert.
I had one more question:

Quote:
>>It is just best that you remember to set you recordsets or any

objects to Nothing when you are done with them.<<

In the past, I have just set recordsets = Nothing.
What aother objects are you referring to in your statement you
mentioned above, and do you have an example of code where other types
of objects are destroyed?  Do you have a list of objects you normally
destroy as a general practice?

Thanks,

Ron



Quote:
> Unfortunately there is no easy way to check all your objects for a
Nothing
> state.  To do so would require public access of all the recordsets
> throughout your application, which is poor programming practice.  It
is just
> best that you remember to set you recordsets or any objects to
Nothing when
> you are done with them.  Also make sure you have an error handle in
every
> subroutine using an object and remember to destroy the object there
also...

> Example:

> Public Function getRecord() As String

>     Dim objDbRs As ADODB.Recordset

>     On Error GoTo ErrorHandle

>     Set objDbRs = New ADODB.Recordset

>     With objDbRs

>         Set .ActiveConnection = gobjMyConnection
>         .Open "select txtRecordValue from tblSample"

>         If .RecordCount > 0 Then
>             getRecord = objDbRs!txtRecordValue
>         Else
>             getRecord = vbNullString
>         End If

>         .Close

>     End With

>     Set objDbRs = Nothing

>     Exit Function
> ErrorHandle:
>     'If an error occurs...  Destroy the Recordset and return a null
>     Set objDbRs = Nothing
>     getRecord = vbNullString

> End Function



> > RE: VB 6

> > I am developing a VB app and have what might appear to be a simple
> > question with a possibly complexa answer.

> > In my app, I am setting my recordsets = "nothing" when I close the
app,
> > but I would like to know if, just prior to closing the app, (on the
> > click event of the "CloseApp" button) if there is a way to check to
see
> > what objects (ie. recordsets, etc) have not been closed and are
stiil
> > open at the close of the app.

> > Does anyone out there have some sample code that can trap and list
what
> > object or variables have not been closed when an app terminates?

> > I want to make sure that when my app closes on the users machine,
that
> > they get back all of their memory my app used.

> > --
> > Thanks,

> > RLN

> > Sent via Deja.com
> > http://www.deja.com/

--
Thanks,

RLN

Sent via Deja.com
http://www.deja.com/



Mon, 14 Jul 2003 03:30:03 GMT  
 Checking for memory leaks (open objects) after app is closed
An object (in the simplest of terms) is a re-usable block of code.  For me
to go any deeper would take way more time then I have.  If you make a class
module in VB you can instantiate it any number of times.  I would encourage
you to purchase some books on Object Oriented coding and Visual Basic to
help out.

Essentially, anything that you have to use the "set" statement to create (or
instantiate) your variable then you should set it to nothing when you are
done.


Quote:
> Thanks for your reply, Robert.
> I had one more question:

> >>It is just best that you remember to set you recordsets or any
> objects to Nothing when you are done with them.<<

> In the past, I have just set recordsets = Nothing.
> What aother objects are you referring to in your statement you
> mentioned above, and do you have an example of code where other types
> of objects are destroyed?  Do you have a list of objects you normally
> destroy as a general practice?

> Thanks,

> Ron



> > Unfortunately there is no easy way to check all your objects for a
> Nothing
> > state.  To do so would require public access of all the recordsets
> > throughout your application, which is poor programming practice.  It
> is just
> > best that you remember to set you recordsets or any objects to
> Nothing when
> > you are done with them.  Also make sure you have an error handle in
> every
> > subroutine using an object and remember to destroy the object there
> also...

> > Example:

> > Public Function getRecord() As String

> >     Dim objDbRs As ADODB.Recordset

> >     On Error GoTo ErrorHandle

> >     Set objDbRs = New ADODB.Recordset

> >     With objDbRs

> >         Set .ActiveConnection = gobjMyConnection
> >         .Open "select txtRecordValue from tblSample"

> >         If .RecordCount > 0 Then
> >             getRecord = objDbRs!txtRecordValue
> >         Else
> >             getRecord = vbNullString
> >         End If

> >         .Close

> >     End With

> >     Set objDbRs = Nothing

> >     Exit Function
> > ErrorHandle:
> >     'If an error occurs...  Destroy the Recordset and return a null
> >     Set objDbRs = Nothing
> >     getRecord = vbNullString

> > End Function



> > > RE: VB 6

> > > I am developing a VB app and have what might appear to be a simple
> > > question with a possibly complexa answer.

> > > In my app, I am setting my recordsets = "nothing" when I close the
> app,
> > > but I would like to know if, just prior to closing the app, (on the
> > > click event of the "CloseApp" button) if there is a way to check to
> see
> > > what objects (ie. recordsets, etc) have not been closed and are
> stiil
> > > open at the close of the app.

> > > Does anyone out there have some sample code that can trap and list
> what
> > > object or variables have not been closed when an app terminates?

> > > I want to make sure that when my app closes on the users machine,
> that
> > > they get back all of their memory my app used.

> > > --
> > > Thanks,

> > > RLN

> > > Sent via Deja.com
> > > http://www.deja.com/

> --
> Thanks,

> RLN

> Sent via Deja.com
> http://www.deja.com/



Mon, 14 Jul 2003 10:02:44 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Checking for memory leaks (open objects) after app is closed

2. When to close recordset objects - Memory Leak?

3. Where can I find memory leak check tool?

4. Checking For Memory Leaks

5. How to check memory leaks ?

6. Memory Leak Checking

7. VB6 app has memory leak after installing IE 6.0 (installation was custom made)

8. Memory leak detector for VB apps?

9. memory leak problem in VB app

10. Memory Leak in app

11. Memory leak on multithreaded client server app

12. Memory Leaks with SQLClient objects

 

 
Powered by phpBB® Forum Software