Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitor Memory Use in Delphi App

I inherited a very large subsystem from a programmer that left the company and the first order of business is to stop the process from running out of memory.

Basically, it is a loop through a dataset, within which we create and destroy a data module that goes off and does lots of work. As long as this data module is created, you can see memory use climbing all the time in Task Manager until it blows up. I seem to recall from an article I read years ago that one shouldn't fully trust what is reported by Task Manager, as the values are estimates and not real-time. So I am looking for alternatives.

Here's what I have tried:

  1. ReportMemoryLeaksOnShutdown := True in my main project file, but it returns nothing. So either it doesn't monitor memory leaked in packages that are loaded dynamically, or the memory gets freed before the app closes.
  2. AQTime. This is supposed to be a very wow product, but I find it completely underwhelming. If I use the allocation profiler, I end up with hundreds of lines containing nothing useful. Just a memory address, size and something along the lines of "VCL standard allocation." It supposedly breaks down the information by routine, but I just get a flat list with no routine info whatsoever. So I don't think it works.

Is there another tool that can help me trace where this memory is allocated and not freed? I've been commenting out little bits of functionality all over the place to see where the problem goes away and checked that everything that is explicitly allocated gets freed, but I still have a leak and it can be quite a frustrating process.

like image 562
Cobus Kruger Avatar asked May 27 '11 09:05

Cobus Kruger


2 Answers

FastMM includes a simple GUI which displays memory usage while the application is running.

An example project is located in the Demos/Usage Tracker directory.

like image 73
mjn Avatar answered Sep 21 '22 15:09

mjn


I absolutely would use AQTime, and NOTHING ELSE to determine memory usage information. Here is an example of the memory usage information I would expect you could find:

  1. Exact line that allocates memory with GetMem, TObject.Create.
  2. Nice counters of object counts and total memory used by various class types.

First things first, let's get the obvious things out of the way:

A. You have to follow AQTime's instructions and set your project settings up, including your compiler and linker settings, as documented well in the help files. Especially you need the Turbo Debugger (TD32) symbols in your linker options, and all the other options setup as you would set up for any other debug build of your project.

B. You should try a tutorial first, before you use this with your own app.

In short, I've used AQTime heavily, and when I've had problems, they have been solveable, so don't give up yet on AQTime. If you can't get your big app working, start by learning how to test a small app, a demo, or a tutorial exercise.

Update: I have just tested it out myself, and I find that I am having trouble even making a basic demo of AQTime 7 with Allocation profiler work as described. I am using AQTime 7.10.380 pro.

like image 35
Warren P Avatar answered Sep 21 '22 15:09

Warren P