Max Home
max at sherman.org.uk
Fri Apr 14 17:47:16 CDT 2006
John, what you are saying is correct. This is what should happen. Please (if you can) report it to MS. No telling how widespread this is. You have isolated one instance but who can tell how many others (?). No wonder we all experience weird behavior completely unexplainable, from time to time. Bet it is written in C or C+. Regards Max -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of John Colby Sent: 14 April 2006 22:38 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