Gonna Build Me a Memory Leak Detector 
Author Message
 Gonna Build Me a Memory Leak Detector

Hello Everyone,

I've been having trouble trapping memory leaks in a very large app my team
is building in VB 5.0.  The problem is probably the result of failing to do
two things:

1. Not always setting object references to nothing.
2. Not always explicitly unloading pictures.

The program is so big now that I don't savor having to go through line by
line hunting for culprits.  I also tried just running the program and using
the Resource Monitor to eyeball memory use, but this is too rough to be of
much good.

So I've decided to build an add-in which will perform memory checks.  If
this add-in works, I will post it for public use.  This is what I want to

1.  Write and add-in that watches VB during run time.
2. Whenever a new procudure is called, I make an API call which tells me
how much system memory is being used.
3. I write this information to a log file, along with a time stamp, the
name of the procedure, the name of the module, and a flag indicating that
this sample was taken at the top of the proc.
4. When a proc ends, I make another log entry identical to the one coming
in, only I flip the flag to mark that its outgoing.
5. Once the program ends, the log is dumped into an mdb file, which will
report on discrepencies in memory in and out.

The data won't always be right, but at least it should give me an idea of
where the largest discrepencies are.

So, some questions:
1. Will this work?
2. What is the API function which returns amount of system memory currently
being used (there HAS to be one)?
3. I've done some reading on the VB 5.0 object model, and there are ways of
editing lines of code through the add-in architecture.  But I can't see any
hooks which will let me get into procs during run time - is this a
show-stopper, or are these things somehow exposed (can I subclass for
4. Is the nature of memory in Win95/NT4 such that having this data will
give me a decent read on memory leaks, or is the whole theory flawed?

PS: If I can't get hooks into procs as they are called during run time, I
am also considering having the add-in edit the code and unedit it
afterwards - I am positive that I can at leat bring it this far.

Any comments, recommendations, caveats, etc. would be greatly appreciated.

Remember, if it works right  (or even if it doesn't), I'll post a copy.

Thanks in advance,


Sun, 30 Jan 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Gonna Build Me a Memory Leak Detector

2. Gonna Build Me a Memory Leak Detector

3. Gonna Build Me a Memory Leak Detector

4. Memory leak detector for VB apps?

5. Building a simple Dataset, Why does Memory Leak?

6. Memory Leaks/Resource Leaks

7. OLE Automation Problems - MEMORY HOG (Memory Leak?)

8. memory leak in vitual memory

9. memory leak on vitual memory

10. Memory Leak -- Out of Memory

11. ADO Memory Leak results in out of memory

12. Memory leaks using shell from VBA with winAPI kernel32


Powered by phpBB® Forum Software