Jim McKeeth
Jim McKeeth

Reputation: 38703

Finding a Memory Bubble

This is either ridiculously simple, or too complex . . . .

In our application there is a form that loads some data from the database and displays it in the grid (putting it simply). When the data is refreshed the total memory usage climbs by about 50K (depending on how much data is displayed no doubt). Sounds like a memory leak, but when we shut down the application, FastMM is set with ReportMemoryLeakOnShutDown := True, and it doesn't report any abnormal memory leaks.

So it appears we have a memory bubble or bag. Something that is accumulating more memory each time it is run. Like a TList that keeps getting new items added to it, but the old ones never get removed. Then in the shutdown process all the items get destroyed. The rows displayed in the grid do not increase, but there are a lot of object lists behind the scenes that make this work, so it could be anywhere.

So my question is if anyone knows of a good trick for finding out what parts of an application are using how much memory . . . . I can think of lots of tedious ways of doing it (which I am in the process of doing - checking each list I can find), so I am hoping someone has a trick or technique I have not thought of.

Thanks in advance!

Update: Every refresh results in an additional 10-50K of memory being used. The users are reporting that eventually the application stops responding. It certainly acts like a memory leak, but FastMM (the memory manager) does not see anything leaking. I'll try some other memory tools . . .

Upvotes: 3

Views: 555

Answers (7)

vcldeveloper
vcldeveloper

Reputation: 7489

As Lars Truijens mentioned, AQTime provides a live memory consumption graph, so in runtime, you can see what objects are using more memory whenever you refresh data.

Upvotes: 0

dmajkic
dmajkic

Reputation: 3488

It looks like there is some memory allocated via custom AllocMem() calls, bypassing FastMM.

This can be midas. Andreas has a solution for this

Or some other InitXXX WinAPI call that allocates something, without freeing. Or some other third-party or windows dll used by project.

Upvotes: 3

Vegar
Vegar

Reputation: 12898

Once I had the same problem. The application was certainly leaking, but I got no report on shutdown. The reason for this was that I had included sharemem in the uses-section of the project.

Have you tried the full FastMM-version? I have found that tweaking its settings gives me a more verbose information of memory usage.

Upvotes: 0

Lars Truijens
Lars Truijens

Reputation: 43595

Tools like AQTime can report difference in memory/object usage between snapshots. This might help you find out what keeps growing.

Upvotes: 6

gabr
gabr

Reputation: 26830

Just F8 through the critical part and look at the process usage graph (Process Explorer from Mark Russinovich works great for that). When you find the culprit method, repeat the process but descend into that method.

Upvotes: 6

Cesar Romero
Cesar Romero

Reputation: 4027

Im not a FastMM expert, but I suppose that after a memory manager get memory, after you free the objects/components, it holds for future use with some zeroes or flag, I dont know, avoiding the need to ask the OS for more memory any time, like a cache.

How about you create the same form/open same data, N times in a row? Will increase 50K each time?

Upvotes: 0

Georg Schölly
Georg Schölly

Reputation: 126105

Does this happen every time you refresh the data or only the first time? If it's only the first time it could be that the system just reserves the memory for your application, despite the fact that it's not used at this time. (Maybe at some point the old and new data existed simultaneously in memory?)

There are many tools which provide you with informations about memory leaks, have you tried a different one?

Upvotes: 0

Related Questions