[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to check for memory leaks in VB6

Posted on 2002-05-28
8
Medium Priority
?
1,560 Views
Last Modified: 2008-02-01
Can anyone tell me how to check for memory leaks in VB6?  According to VB documentation you should manually release the resources of all dynamically created variables with

  Set variable = Nothing

but what if I forget a few of these?  C++ has some nice diagnostic routines that report this kind of info, but what about VB6?  No book that I have ever seen on VB6 discusses this topic.  You can hardly find the word "memory" in the index of books on VB6.
0
Comment
Question by:ASP_Ray
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Accepted Solution

by:
gencross earned 300 total points
ID: 7039443
As far as I know the only way to do this is to purchase third party tools.  There is a nice one from NuMega called Bounds Checker.  I think it is somewhat expensive, but you may be able to find another on one of the download sites.

Hope this helps.
0
 
LVL 4

Expert Comment

by:gencross
ID: 7039445
BTW...

You should be able to get a lot of hits searching the net on "Bounds Checker"
0
 
LVL 2

Expert Comment

by:Crin
ID: 7039658
I made it quite easy for me but with a little programming.

I defined global long variable lngObjCounter, in each class Initialize routine added
lngObjCounter = lngObjCounter + 1
Terminate routine:
lngObjCounter = lngObjCounter - 1

Actually, this helped a lot, but later I wrote own custom bound checker which write class name to some file with mark "+" on Initialize event and "-" on Terminate event.
Simple counting routine then helped me to find leaks.

Sincerely,
Crin


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 26

Expert Comment

by:EDDYKT
ID: 7039940
I'm not sure that will help you


Private Type MEMORYSTATUS
    dwLength As Long
    dwMemoryLoad As Long
    dwTotalPhys As Long
    dwAvailPhys As Long
    dwTotalPageFile As Long
    dwAvailPageFile As Long
    dwTotalVirtual As Long
    dwAvailVirtual As Long
End Type
Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim MemStat As MEMORYSTATUS
    'retrieve the memory status
    GlobalMemoryStatus MemStat
    MsgBox "You have" + Str$(MemStat.dwTotalPhys / 1024) + " Kb total memory and" + Str$(MemStat.dwAvailPageFile / 1024) + " Kb available PageFile memory."
End Sub



or



Private Type LARGE_INTEGER
    LowPart As Long
    HighPart As Long
End Type
Private Type MEMORYSTATUSEX
    dwLength As Long
    dwMemoryLoad As Long
    ullTotalPhys As LARGE_INTEGER
    ullAvailPhys As LARGE_INTEGER
    ullTotalPageFile As LARGE_INTEGER
    ullAvailPageFile As LARGE_INTEGER
    ullTotalVirtual As LARGE_INTEGER
    ullAvailVirtual As LARGE_INTEGER
    ullAvailExtendedVirtual As LARGE_INTEGER
End Type
Private Declare Function GlobalMemoryStatusEx Lib "kernel32.dll" (ByRef lpBuffer As MEMORYSTATUSEX) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Form_Load()
    'KPD-Team 2001
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim MemStat As MEMORYSTATUSEX
    Dim TotalPhys As Currency
    'initialize structure
    MemStat.dwLength = Len(MemStat)
    'retireve memory information
    GlobalMemoryStatusEx MemStat
    'convert large integer to currency
    TotalPhys = LargeIntToCurrency(MemStat.ullTotalPhys)
    'show result
    MsgBox "Current memory load: " + CStr(MemStat.dwMemoryLoad) + vbCrLf + _
             "Total RAM: " + CStr(Int(TotalPhys / 1024 ^ 2)) + " Mb.", vbInformation
End Sub
Private Function LargeIntToCurrency(liInput As LARGE_INTEGER) As Currency
    'copy 8 bytes from the large integer to an empty currency
    CopyMemory LargeIntToCurrency, liInput, LenB(liInput)
    'adjust it
    LargeIntToCurrency = LargeIntToCurrency * 10000
End Function
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 7039949
Of course, you can alway use Performance monitor to monitor the memory leak on your task.

ie. on add counters dialog, select Process on Performance ocject and select private bytes on your task. Then add
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 7040307
learning
0
 
LVL 2

Expert Comment

by:corvanderlinden
ID: 7041107
I would recommend SmartCheck from Numega (www.compuware.com)
0
 
LVL 1

Author Comment

by:ASP_Ray
ID: 7221492
A lot of really great info was given here but although I have not bought it, the recommendation that seems like it might really do what I want is SmartCheck.  The problem is it is sold only as part of a suite of development tools "DevPartner for Visual Basic".  I was told that "BoundsChecker" is a Visual C++ tool.  Thanks everybody.  Wish I could give points to all.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question