We help IT Professionals succeed at work.

VB - Debugging Memory Leaks

2,333 Views
Last Modified: 2013-12-14
Can someone tell me if there is a way I can debug memory leaks in vb6?  I have a message that comes up...

the application tried to referece memory at ....... (or something like it).  vb closes and I must restart my application.

It does not occur in the same place.  It is very random.  Sometimes it occurs after 5 or so minutes of running.  Other times it is after a few hours of running.

I am about to go live with my ap, so it is very urgent that I solve this problem ASAP.

Thanks
Comment
Watch Question

Commented:
Tell us a little bit more about what you are doing with the program.  Are you:

- Interacting with other COM components
- Calling out to DLL's (e.g. Win32 API calls)
- Using MDAC or other data access components

Have you tried running the code on other systems to make sure the problem isn't isolated to the workstation on which you are developing?
Have you installed Visual Studio SP5?  Current Operating System Service Packs?  If you are interacting with other software, is it or can it be patched?

Also, you can use Performance Counters to observe the memory growth over time of the various processes involved.

Hope this helps,
-B

Author

Commented:
What are performance counters and where can I find more about them?

Windows 2000 SP3
VS6 SP5

Yes I have used it on another workstation, same problem.

I'm using a combobox control which allows me to type or select.  I downloaded this control from the web.  I believe it has something to do with this since my other aps don't seem to have problems.  It is very difficult to recreate since it happens periodically.  I am only using one other component (MSHFlexGrid).  I am accessing a MSDE database using ADO.

My CPU usage also periodically goes to 100% when running the ap.  Again it is random.

To actually debug, you could try the following:

Install the debugger from Visual C
 (as you mention Visual Studio I assume you have it)
  as your system debugger

When compiling your app, Check 'Create Symbolic Debug Info'
on the Compile tab of Project Properties.

Now when the memory exception occurs, you should have the possibility
  to let it start up the debugger.

Apart from disassembly code, this could have some VB-code
 (from the Symbolic Debug Info) that could give you a clue as to where the error
occured.

Commented:
Are you by any chance using MDAC 2.6?  If so, try downloading 2.7 from Microsoft and see if that helps.  I had a similar problem with handle leaking once and this fixed it.

Hope this helps,
-B

Author

Commented:
Right now I'm using SQL Server 2000 on my development machine.  When I'm running the ap in production it will be using MDAC.  I will remember to only use 2.7 thanks for the advice.

Commented:
When you install SQL Server 2000, you get MDAC 2.6.  You mentioned that you were using MSDE, so I suspect that's exactly what you have.  Try the upgrade to MDAC 2.7 (or 2.8 is available now, but I haven't tried it).  Here's the link where you can find them:

http://msdn.microsoft.com/library/default.asp?url=/downloads/list/dataaccess.asp

Author

Commented:
But isn't MDAC the same as SQL Server?  I thought if I had SQL Server there was no need to have MDAC (on my developement machine).  But when I install this on production machines I will be using MSDE.

Author

Commented:
I really don't think my memory errors have anything to do with that.  I am using my databases on several different applications without any problems.  I think it has to do with a control I downloaded from the web.  I just have no idea how to test it, or narrow it down.  The error occurs very randomly (ie. sometimes after 2 hours, sometimes after 5 minutes.  Occurs in different areas of the code, so I can't pin point it to one coding error).
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
Do you use array of controls in your program?
I had a similar problem because of an heavy use of array of controls

Commented:
checkout
gflags

goto Start->Run->gflags
... will give u everything u want

Commented:
Did your project optimize remove some overflow checks when compiled?
It may cause memory leak if the codes have bugs..

Author

Commented:
I don't have gflags.  Where do I find this?

Author

Commented:
I am not using an array of controls.

Mingz,
Can you explain your suggestion.

Commented:
project->project properties

In the compile tab
click on advance optimizations....

uncheck all checks

hope that it will work :)

Author

Commented:
There was nothing checked to begin with.

Thanks for the prompt suggestion.

Author

Commented:
Can someone explain to me what gflags are?  I can't seem to do what bvrocks suggested.

Thanks
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.