Strings seem to be leaking in FindMapFile..DecodeUtf8

delphi package - automated exception handling
Post Reply
Krom
Posts: 2
Joined: Wed May 24, 2017 4:55 am

Strings seem to be leaking in FindMapFile..DecodeUtf8

Post by Krom »

madExcept is an excellent tool, thank you for that!
However, there seems to be string "leak". Could you please take a look?

I've written a simple app with madExcept and FastMM4 that runs 24/7.
It connects to DB every minute and runs a stored procedure. So far so good.
Sometimes DB will be offline, so there's a timeout EOleException. madExcept logs it. Good too.

Now after several days there are 6 exceptions logged and FastMM4 reports that there are 17703 UnicodeStrings allocated.
Those strings seem to be "leaking" in big chinks. So the first day it's 260 strings, the second 260, the third - 17703.
I'm not sure if they are connected with exceptions logged by madExcept, but here is the allocation log:

Code: Select all

--------------------------------2017/5/24 7:32:15--------------------------------
Allocated block logged by LogAllocatedBlocksToFile. The size is: 68

This block was allocated by thread 0x18EC, and the stack trace (return addresses) at the time was:
40697A [System.pas][System][@GetMem$qqri][4305]
409FB7 [System.pas][System][@NewUnicodeString$qqri][23462]
40B1F3 [System.pas][System][@UStrSetLength$qqrr20System.UnicodeStringi][28745]
41D090 [madStrings][DecodeUtf8$qqrx27System.%AnsiStringT$us$i0$%]
430C6E [madMapFile][ReadPackedString]
43133B [madMapFile][Public_LoadFromStream]
431945 [madMapFile][ImportStr]
431A9A [madMapFile][GetMapFileFromResources]
4347C3 [madMapFile][TMapFile.$bctr$qqrox27System.%AnsiStringT$us$i0$%x20System.UnicodeStringuioo]
435C62 [madMapFile][FindMapFile$qqrpv]
77C30000 [Unknown function at RtlTryAcquireSRWLockExclusive]

The block is currently used for an object of class: UnicodeString

The allocation number is: 51550368
There are 40mb of these sections, each looking the same.
Which makes me think, that somehow strings get instantiated, but never get freed till the app is closed.

Could you lease take a look into this, is there a reason and a fix, why strings keep on being allocated and never freed?
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Strings seem to be leaking in FindMapFile..DecodeUtf8

Post by madshi »

When an exception occurs, madExcept loads the map file information (function names and line numbers) for each module (exe/dll) that is listed in the callstack. This map file information is cached, to improve performance. However, at process shutdown, the cache should be cleared/deallocated, so I'm not sure why FastMM4 should report it as a leak. Have you tried madExcept's leak reporting? Does it produce the same leak complaints?

Just to make sure there are no misunderstandings: Once all modules with map file information are in the map file cache, the cache should not grow, anymore. So it's not like every new exception will keep on adding RAM leaks.
Krom
Posts: 2
Joined: Wed May 24, 2017 4:55 am

Re: Strings seem to be leaking in FindMapFile..DecodeUtf8

Post by Krom »

Thanks for your reply!

No it does not get reported as Leaked on app closed.
This is not a true leak, hence I included into "-s. Sorry if I'm being not very clear.
It seems to eat up memory of a running app, without releasing it till app is closed. Which is fine for short-lived app, but could be problematic for 24/7 one.

Please give me another week, I'll see if more strings get allocated.
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Strings seem to be leaking in FindMapFile..DecodeUtf8

Post by madshi »

Well, as I said, the memory should not pile up endlessly during runtime. Once all map files are loaded, no further "leaks" should occur. If you find otherwise, please let me know.
Post Reply