I have an application that I would like to track its memory usage.
The problem is that there is a memory leak or memory is not being
deallocated someplace and I'm trying to find the culprit.
The application uses tcom to connect to Excel and to another DLL that
provides methods to read and process a particular type of file. The
application loops over hundreds of the files, reads them, and
generates a spreadsheet for each.
The application uses unset to free up as much memory as possible.
However, the memory footprint continues to grow with every file. With
processing some sets of files, the application dies because Tcl can't
allocate any more memory. At that point the memory usage of the
application is up to 2 GB!
I'd like to figure out if tcom, Excel, the DLL, or something else is
the problem with the memory usage. Is there some way to monitor how
the memory is being used? I'm use Tcl Dev Kit to wrap my application
on Windows. There isn't a Linux version.
Any suggestions would be greatly appreciated.
Thanks,
Bob Lipman
http://cic.nist.gov/lipman/
Tracking leaks in extensions is already challenging; add COM to the
picture and it gets interesting ;-)
One thing to do though would be to make sure that the Tcl part is
flawless. Since Tcom's objects use the bold EIAS-violating approach of
freeing COM objects as soon as the refcount goes to zero, the upside
is that it's more likely to do 'early frees' than leaks. So making
sure all your vars holding tcom objects are freed, is an important
step. [info globals] is your friend. You did that, right ?
Now if nothing comes out of this first step, the next thing would be
to try to isolate the culprit between tcom and the extra dll. For this
I'd cut out the "extra dll" calls, replacing them with dummy code, but
leaving the tcom part and the script logic untouched.
As a last resort of course, I'd work around the whole thing by using a
short-lived process, working on a single file and exiting, launched in
a loop by a parent process. Of course it's only doable if the process
creation overhead is small wrt useful processing.
HTH,
-Alex
Have you taken a look at http://wiki.tcl.tk/memory ?