Click to See Complete Forum and Search --> : Memory of the process


Spotnick2
June 22nd, 2001, 12:23 PM
I have a memory leak in my application and I want to find it of course..

What is the way to track the memory of the current process in VB? I mean, I do have API functions to get the amount of free memory, but that implies other applications and services doesn't eat memory when I'm testing...

Thank you!

Iouri
June 22nd, 2001, 01:18 PM
Before running the program start Resource meter and check how much memory your app uses. You will find recource meter in Program/Accescories/System Tools.

Iouri Boutchkine
iouri@hotsheet.com

Spotnick2
June 22nd, 2001, 03:54 PM
Actually, this wouldn't have been useful.

I found everything I needed with the GetProcessMemory API function...

For readers:


Type PROCESS_MEMORY_COUNTERS
cb as Long
PageFaultCount as Long
PeakWorkingSetSize as Long
WorkingSetSize as Long
QuotaPeakPagedPoolUsage as Long
QuotaPagedPoolUsage as Long
QuotaPeakNonPagedPoolUsage as Long
QuotaNonPagedPoolUsage as Long
PagefileUsage as Long
PeakPagefileUsage as Long
End Type

private Declare Function GetCurrentProcess Lib "kernel32" () as Long
private Declare Function GetProcessMemoryInfo Lib "psapi.dll" (byval lHandle as Long, lpStructure as PROCESS_MEMORY_COUNTERS, byval lSize as Long) as Integer




and in your function:


Dim lngReturn as Long
Dim typMem as PROCESS_MEMORY_COUNTERS

lngReturn = GetProcessMemoryInfo(GetCurrentProcess(), typMem, len(typMem))
Debug.print CStr(typMem.WorkingSetSize)




This works like a charm...! I found the ADO connection was leaking memory for some reason... even if I closed it and set it to nothing!