Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to analyze excessive memory consumption (PageFileUsage) in a Delphi Application?

This is a follow-up to this question: What could explain the difference in memory usage reported by FastMM or GetProcessMemoryInfo?

My Delphi XE application is using a very large amount of memory which sometimes lead to an out of memory exception. I'm trying to understand why and what is causing this memory usage and while FastMM is reporting low memory usage, when requesting for TProcessMemoryCounters.PageFileUsage I can clearly see that a lot of memory is used by the application.

I would like to understand what is causing this problem and would like some advise on how to handle it:

  • Is there a way to know what is contained in that memory and where it has been allocated ?
  • Is there some tool to track down memory usage by line/procedure in a Delphi application ?
  • Any general advise on how to handle such a problem ?

EDIT 1 : Here are two screenshots of FastMMUsageTracker indicating that memory has been allocate by the system.

  • Before process starts:

Before process starts

  • After process ends:

After process ends

Legend: Light red is FastMM allocated and dark gray is system allocated.

I'd like to understand what is causing the system to use that much memory. Probably by understanding what is contained in that memory or what line of code or procedure did cause that allocation.

EDIT 2 : I'd rather not use the full version of AQTime for multiple reasons:

  • I'm using multiple virtual machines for development and their licensing system is a PITA (I'm already a registered user of TestComplete)
  • LITE version doesn't provide enough information and I won't waste money without making certain the FULL version will give me valuable information

Any other suggestions ?

like image 995
jonjbar Avatar asked Feb 21 '23 03:02

jonjbar


1 Answers

Another problem might be heap fragmentation. This means you have enough memory free, but all the free blocks are to small. You might see it visually by using the source version of FastMM and use the FastMMUsageTracker.pas as suggested here.

like image 66
Lars Truijens Avatar answered Feb 23 '23 18:02

Lars Truijens