[AccessD] Tracking down memory leak

jwcolby jwcolby at colbyconsulting.com
Thu Jan 22 12:57:57 CST 2009


First of all you must CLOSE all recordsets.

Next, you need to make sure you are not copying a pointer to 
a recordset to another variable.  An object is not destroyed 
until the LAST pointer to the object is set to nothing.  IOW 
if I create a recordset, then pass the recordset off to 
another piece of code, and that piece of code STORES the 
pointer, now I have TWO pointers to the recordset.  BOTH 
pointers have to be set to nothing before the object is 
destroyed.

And finally, understand that every bound form, combo, list 
etc uses a DAO recordset.  Basically anything that uses a 
table or query.  Thus a form with 20 combos has at least 21 
recordsets opened.

John W. Colby
www.ColbyConsulting.com


McGillivray, Don [IT] wrote:
> Hi, All
> 
> I'm looking for guidance on identifying the source of a memory leak in an application.  I've already gone through my code to ensure that each "Set ObjVariable =  . . . " statement is accompanied by a "Set ObjVariable = Nothing" statement.  All my procedures use error handling, and are forced to exit through a substructure that contains the proc's "Set ObjVariable = Nothing" statements, ensuring that the object variables are set to nothing even when an error occurs.
> 
> As the app runs, both memory usage and the handle count slowly creep up over time - the handle count faster than the memory usage.
> 
> I did a simple experiment by monitoring handle usage while opening and closing a single table in a database several times.  I noticed that at first the handle usage was variable, but that after several repetitions it more or less stabilized.  Something like this:
> 
> Rep             State           Handles
> =================================
> 0               Initial 195
> 1               Open            203
> 1               Closed  199
> 2               Open            203
> 2               Closed  200
> 3               Open            202
> 3               Closed  200
> 4               Open            201
> 4               Closed  200
> 5               Open            210
> 5               Closed  204
> 6               Open            207
> 6               Closed  204
> 7               Open            206
> 7               Closed  201
> 8               Open            204
> 8               Closed  201
> 9               Open            204
> 9               Closed  201
> 
> For grins, I left the db open and idle overnight.  When I checked this morning, its memory usage had gone from 20.7 MB to 3.7 MB.  Upon opening the table, the usage went to 7.8 MB and stayed around there after several open/close repetitions.
> 
> So, now I'm more confused than when I started.  How exactly does one detect memory leak, and once detected, how to find its source?
> 
> Anybody out there with nothing better to do than to educate my weak brain?
> 
> Don
> 
> This e-mail may contain Sprint Nextel Company proprietary information intended for the sole use of the recipient(s). Any use by others is prohibited. If you are not the intended recipient, please contact the sender and delete all copies of the message.
> 
> 



More information about the AccessD mailing list