Dear Sir/Madam,

How to measure memory consumption of a VB 6.0's programe?

As a programmer in vb. 6.0, where i have to be conscious for getting less consumption of memory of my program at design time?

Is there any free software to measure memory consumption of a programe?

Please guide me Sir/Madam

Dani AI

Generated

Quick summary and a practical approach that builds on ’s clarification (you want runtime memory) and ’s pointers: measuring a VB6 program well means watching the right counters, exercising the code under repeatable conditions, and knowing common VB6 leak sources so you can debug them.

Measure the right things — Working Set (physical RAM) and, more importantly for leak detection, Private Bytes (committed private memory). Task Manager shows a crude snapshot; use Performance Monitor (perfmon) or Sysinternals Process Explorer to graph Process\Private Bytes and Process\Working Set while you run repeatable scenarios. A steady climb in Private Bytes after repeated operations usually indicates a leak.

Common VB6 leak sources to check before assuming a runtime bug: circular references between objects/WithEvents, ActiveX/OCX controls that don’t release, API allocations (LocalAlloc/GlobalAlloc, CreateCompatibleDC/CreateDIBSection) not freed, and unreleased GDI objects. When a leak appears, isolate it with a binary-search test (disable half the features) and create a minimal repro. Always Set obj = Nothing for COM objects, call Close/Release methods on libraries, and free API resources with the matching Delete/Release calls.

If you want an in-process, reproducible readout, this VB6 snippet reads current process memory (WorkingSet) and returns MB. Use it during debug loops or automated tests to log trends:

Public 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

Public Declare Function GetCurrentProcess Lib "kernel32" () As Long
Public Declare Function GetProcessMemoryInfo Lib "psapi.dll" (ByVal hProcess As Long, ByRef pmc As PROCESS_MEMORY_COUNTERS, ByVal cb As Long) As Long

Function GetWorkingSetMB() As Double
  Dim pmc As PROCESS_MEMORY_COUNTERS
  pmc.cb = LenB(pmc)
  If GetProcessMemoryInfo(GetCurrentProcess(), pmc, pmc.cb) <> 0 Then
    GetWorkingSetMB = pmc.WorkingSetSize / 1024# / 1024#
  Else
    GetWorkingSetMB = -1
  End If
End Function

Use the code to log values before/after operations and combine that with PerfMon/Process Explorer to pinpoint leaks.

Recommended Answers

All 8 Replies

Hi P.manidas,
What type of memory you want to read/measure? Do you mean to say Memory used for storing or memory used while running your program?

Thanks

Hi P.manidas,
What type of memory you want to read/measure? Do you mean to say Memory used for storing or memory used while running your program?

Thanks

Dear Kinwang2009,

Here i am asking about 2nd one. How much memory will be consumed at the time of running the programe.

Thank you for your query.

Time to use your friends (yahoo, google, ask, answers, bing) and search for vb6 ReadProcessMemory or you could use the task manager to see how much your program takes up in memory...

Good Luck

Time to use your friends (yahoo, google, ask, answers, bing) and search for vb6 ReadProcessMemory or you could use the task manager to see how much your program takes up in memory...

Good Luck

Dear vb5prgrmr,

First of all thanks for your reply, vb4prgrmr.

As you have written, i have seen in the Task Manager regarding memory used by the programe. If it shows perfect result, then it's OK.

And what about the precaution to take at design time for less memory consumption by the programe/software? And rest of all i will search with my friend as you have written.

Thank you

Precautions in designtime to consume less memory... (you would watch the vb6.exe memory consumption in debug mode...)

Use control arrays as much as possible.
Don't over crowd forms with controls.
If you can, put as much code into modules and classes as you can as the forms graphical elements take up a lot of memory.
When using data access methods and you have a table with an extreme amount of records, don't use a select * unless you absolutly have to for your program.
When you can unload formname/set formname = nothing to totaly remove it from memory.
And this goes with the one above... Don't use public variables in the forms because if you need access to the information contained within that variable, you have to keep at least part of the form loaded. So put the public variable in a module and that way you will have access to it from everywhere when you need it.
Don't load an excessive amount of graphics into memory (icons, who cares, but pictures like bmp's, jpeg's, and the like, yeah you gotta watch those).
The same thing can be said about files you open up, meaning text files and such that you open with the Open Method.
When you can, use an image control instead of a picturebox control or a label instead of a textbox... i.e. use the lightest weight control you can for the purposes needed at hand...

Good Luck

Dear vb5prgrmr,

Thank you for your reply with lot more information. It's really help me.

Thank you vary much.

Not a problem, now if this is solved could you please mark it as so...

Good Luck

No problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.