Recent

Author Topic: how to track down a growing memory use that is not a memory leak (solved)  (Read 615 times)

mas steindorff

  • Sr. Member
  • ****
  • Posts: 428
I have an app that uses TCollection, TCollectionitem, and Tstringlist heavily.  when i run the app, I can see it's memory use increase with the windows "resource monitor" and the program slows down.  the strange thing is I only really allocate memory on startup where the TCollection is populated and each TCollectionitem's 3 tstringlist are created.  otherwise there are a lot of local create and free operation local to the main code at the procedure level.
I have no memory leaks reported by the Heaptrc debug option but it does see the large memory use. (both 32 & 64 bit)

I'm thinking it's may be due to me sorting my Tcollectionitems which I do a lot of. I'm thinking I will need to bracket my code with some sort of call to getfpcheapstatus() or simuler.

Does anyone have any other (simpler) suggestions on how to track this bug down?   
« Last Edit: June 08, 2019, 12:47:20 am by mas steindorff »
windows 7/10 - laz 2.0 / 1.2.6 general releases

lucamar

  • Hero Member
  • *****
  • Posts: 2076
Re: how to track down a growing memory use that is not a memory leak
« Reply #1 on: June 07, 2019, 03:42:03 am »
Do you add lines to the string lists over time? That may be one reason.

Simply sorting the colection shouldn't cause more than a temporal increase unless some object isn't getting destroyed when it should--but then you'd have a memory leak somewhere.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

mas steindorff

  • Sr. Member
  • ****
  • Posts: 428
Re: how to track down a growing memory use that is not a memory leak
« Reply #2 on: June 07, 2019, 04:00:05 am »
Do you add lines to the string lists over time? That may be one reason.
no, they are modified, but always have less than 10 strings each.  I do use tstr[n] :='new string'; where I need to change the the value of an exciting string.  I can imagine that would trigger a new memory allocation but all of my strings are short (first names of members).

I have 3 different ways of sorting the Tcollection and do so 10,000++ times a run.  I'm letting the Tcollection sort itself by using it's .sort(@sortfunction) and simply point to a different function each time.
I see this program slow down issue when I run continuously for a few seconds. I can see a small increase in memory usage for each run so I ,at least, have a path to debug.
windows 7/10 - laz 2.0 / 1.2.6 general releases

lucamar

  • Hero Member
  • *****
  • Posts: 2076
Re: how to track down a growing memory use that is not a memory leak
« Reply #3 on: June 07, 2019, 06:55:36 am »
Perhaps you should try to track each allocation/deallocation of collection items and make sure there is no code in the sorting routines duplicating items.

Other than that I can't say. It's difficult to guess what can be wrong (if anything) without seing some code.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

mas steindorff

  • Sr. Member
  • ****
  • Posts: 428
Re: how to track down a growing memory use that is not a memory leak
« Reply #4 on: June 08, 2019, 12:46:37 am »
thanks for the offer to help but I was more after a debugging approach rather than a solution.
I went with the GetFPCHeapStatus debug approach and found the issue.  All of the pascal objects worked just like they should including ...

:-[ my debug memo I had on another form  :-[
(it was growing larger with debug printouts from each new run)
windows 7/10 - laz 2.0 / 1.2.6 general releases

lucamar

  • Hero Member
  • *****
  • Posts: 2076
 :D Happens to the best; one sees the forest and misses the individual trees. :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.