0

I am experiencing a non normal memory consumption from my application written in Delphi 10 Seattle. It is a client server fat client type of application using SDAC's Devart as DB component.

I am not aware of specific tools, but I would like to know what causes the memory consumption.

What I observe is the following: as i launch a command the memory used by the exe grows a lot (up to 1 GB, in an app that used to use up to 200MB max) and sometimes this ends in an out of memory error. The stack trace of the out of memory error is of no use and seems random.

Could anyone please suggest a technique to study memory consumption?

I am currently studying memory leaks with FastMM4 and I managed to remove some, but there are just minor ones (TStringlist or some small TBitmap), nothing that justifies 1GB of memory consumption.

Is there a way to say "unit4.pas allocated 100MB of RAM" or any other similarly useful memory usage report?

Thanks a lot.

I feel stuck since I do not know the tools for this task.

UnDiUdin
  • 14,924
  • 39
  • 151
  • 249
  • 1
    Do you query database table columns with a BLOB type? If yes then figure out the largest datasets and see if avoiding them avoids memory consumption. [With PHP 7.1 I had a similar problem with MySQLi on TEXT columns](https://bugs.php.net/bug.php?id=71468#1487152385) ([older bug](https://bugs.php.net/bug.php?id=51386) and [Longtext max memory error using mysqli_query](https://stackoverflow.com/a/47204427/4299358)). – AmigoJack Feb 22 '22 at 20:41
  • Some information on sizes and # of current allocations: https://stackoverflow.com/questions/1701671/how-to-monitor-or-visualize-memory-fragmentation-of-a-delphi-application/1701917 – Brian Feb 22 '22 at 20:57
  • 1
    FastMM will only find leaks, not consumption (which I think you're aware so sorry to repeat). I think @AmigoJack is on the right track, check what your db is doing.. my hunch is you are fetching a lot of records to the local machine, or your fetching records into local arrays etc. Let us know. – John Easley Feb 23 '22 at 03:04
  • 1
    This is a typical example of a question that can only be answered with speculative guesses, and is therefore not a good fit on SO. You should trace into your program starting from "as i launch a command" to look for the massive memory usage. We don't know what that command is or what it does. – Tom Brunberg Feb 23 '22 at 07:09
  • Try that https://www.tmssoftware.com/site/blog.asp?post=895 – Delphi Coder Feb 23 '22 at 09:57
  • 1
    @TomBrunberg Since I don't believe my answer to be a "speculative guess", I'd tend to disagree with you. – Ken Bourassa Feb 23 '22 at 14:09
  • @AmigoJack I thought to be expert enough on this subject but once more it was because of a BLOB. You comment made me notice a field that was not a blob in the past and now it is. Problem solved, if u answer I will accept it! – UnDiUdin Feb 23 '22 at 16:16
  • @TomBrunberg i disagree with you, in this case the comments inspired me, for the same reason this answer can inspire others in the future. I am so happy since I was really worried about this issue. – UnDiUdin Feb 23 '22 at 17:15

2 Answers2

1

What you need is a good memory/allocation profiler.

I don't know what features are typical or not in such a profiler because I only ever used one, but the one I use allows to get a report at anytime during a run that shows all the allocated memory and where in the application said memory was allocated.

Ken Bourassa
  • 6,363
  • 1
  • 19
  • 28
1

Do you query database table columns with a BLOB type? If yes then figure out the largest datasets and see if avoiding them avoids memory consumption. With PHP 7.1 I had a similar problem with MySQLi on TEXT columns (older bug and Longtext max memory error using mysqli_query).

Actually solving/preventing the memory consumption can surely be done - the database abstraction layer surely knows an alternative method to query such columns in a way that works better for both sides: server and client. Feel free to edit this answer to include your actual code.

AmigoJack
  • 5,234
  • 1
  • 15
  • 31
  • Thanks for the pointer. In fact I was inspired from your answer to check for blobs in the queries and I found a "forgotten" query in some remote part of the code that was really querying a blob field, by the way a field that used to be a text field and that in time become a blob field so the query kept reading from it. Anyway my problem is solved now, I will search for blobs manually in all queries. My app is a legacy app in which there are no layers, so queries are scattered bnut since the app has a value for the user my task is to maintain it and make it better and better day by day. Thanks! – UnDiUdin Feb 23 '22 at 21:13