Board index » delphi » Help -- can SaveToFile really cause a Memory Leak!???

Help -- can SaveToFile really cause a Memory Leak!???

I'm having a really confusing problem!  After taking weeks to track
down a memory leak, I seem to have isolated the problem to the
SaveToFile method associated with a TString from a TListBox.  When I
comment out the SaveToFile line, there is no memory leak.  When the
line is uncommented out, the SaveToFile method does save the TString
to disk as it is supposed to, but it also seems to allocate an
additional amount of memory equal to the size of TString.  As this
SaveToFile line is called approximately every 15 seconds, you can
understand how quickly this adds up, causing Win95 swapfiles exceed
100megabytes in little over a day of continuous running!  Does anyone
have any idea why this is happening?  I use SaveToFile elsewhere, but
it does not seem to do this anywhere else.  I can always try a simple
hack, which would be to write the file to disk myself in my own
routine (rewrite ... closefile), but I'd rather solve this wacko
problem.  Any help or ideas would be much appreciated!

  Thank you.

 

Re:Help -- can SaveToFile really cause a Memory Leak!???


Quote
APM wrote:

> I'm having a really confusing problem!  After taking weeks to track
> down a memory leak, I seem to have isolated the problem to the
> SaveToFile method associated with a TString from a TListBox.

APM?,
I am not aware of this particular problem but in my company we have
written years ago a DOS driver that communicates with external
instruments, and it have worked well for years, until we switched to
W95. Then, each time we did an access to the driver (which is usually
done by the succession assign, rewrite, write, close) a memory leak
occured. Since we do this several times a second, you imagine the
consequences! They contacted Microsoft who acknowledged this was a bug,
but they had no plans to correct it. So we had to find a workaround
solution. It consisted in writing a DLL that opened the driver (=file)
at the beginning of the session and closed it at the end. This DLL could
serve several applications that used the same driver to communicate to
outside the PC, thanks to a mailbox scheme implemented in the DLL.
I am sorry not to bring you an explanation, but I think you should not
be surprised to find bugs of that kind, though all the qualities we find
to W95.
Jean-Marc

Other Threads