[AccessD] Memory leak

Jim Lawrence accessd at shaw.ca
Fri Apr 14 19:48:05 CDT 2006


John:

You have definitely demonstrated a memory leak. There appears to be some
unresolved problems with the Access object handler. Is there just another
pointer created when a duplicate object is created, similar to when using
the 'clone' method or is the new object recreated in its entirety? 

All that I am saying it is unlikely that you or I would have caused a
similar error without trying.

Jim

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of John Colby
Sent: Friday, April 14, 2006 2:38 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Memory leak

Jim,

The point is to demonstrate that a simple call to a function, passing in a
reference to the connection object, CAUSES a memory leak.  When passing
anything other than a simple data type in to a function, VBA passes by
reference, i.e. a pointer to the object.  Passing by reference causes the
pointer to the object to be placed onto the stack being built for the
function call.  When the code inside of the function starts to execute, it
can reference these objects on the stack.  As the function exits, the stack
is supposed to be cleaned up by the interpreter, destroying all pointers to
objects on the stack.

Thus my code should not consume ANY memory long term.  Pass in a pointer to
an ADO recordset instead of the ADO connection object.  There is no memory
leak (as there should not be).

All my code is doing is calling a function over and over.  IF the stack is
cleaned up properly, NO memory is used.  Change the data type to a string, a
long, a variant etc.  You will see NO memory leak.  Pass in a pointer to an
ADO connection and you will see a memory leak.

John W. Colby
www.ColbyConsulting.com 


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence
Sent: Friday, April 14, 2006 3:20 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Memory leak

Hi John:

I would think that it would at the least and at the most consume all
available memory. 

The call to the ' FWInit CurrentProject.Connection ' should either be above
or below the 'While' loop.

A better was to the loop would be 
 
Function TestFWMemLeak()
    Dim BreakLoop as Boolean
	
    BreakLoop = True
	
    While BreakLoop = True
        DoEvents
        BreakLoop = FWInit CurrentProject.Connection
    Wend
End Function

Public Function FWInit(lCodeProjConn As ADODB.Connection) As Boolean

    ... 'etc....
    
    FWInit = False
	
End Function

Jim

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of John Colby
Sent: Thursday, April 13, 2006 7:14 PM
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] Memory leak

I have just discovered that the following code causes a memory leak:

Function TestFWMemLeak()
    While 1
        DoEvents
        FWInit CurrentProject.Connection
    Wend
End Function
Public Function FWInit(lCodeProjConn As ADODB.Connection) End Function

Open task manager and keep it on top.  Find MSAccess and watch the memory
usage.  As you run TestFWMemLeak the memory usage climbs steadily.

When I google "memory leak ADODB.Connection" I get a ton of hits, though not
this specific issue.

John W. Colby
www.ColbyConsulting.com 


--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list