-1

How does one best identify memory not released properly during run time? I know of several programs that identifies allocated and non freed (leaked) memory when the application closes. But my issue seems to be that during the program execution (possibly a thread) creates some objects that are not freed, although they should be after the system is done with the "work".

Keeping the system running this builds up over time. But when the program shuts down the memory seems to be freed correctly and thus never reported as a leak in MadExcept that I use at the moment.

How do I best go about to detect what is allocating this memory every time the "work" is run and not freeing it until program termination? This is in quite a large server system with around 1 million lines of code, several DLL sub projects and multiple threads running (40-50).

Perhaps there is some system that could identify allocated objects that have been alive for longer than X min. Let's say 60 min is selected and the system left running. Then this information could be used to locate many of these long living objects and investigate those?

inquam
  • 12,664
  • 15
  • 61
  • 101
  • Maybe you could use [Boehm's GC](http://www.hboehm.info/gc/) at least in its leak detector mode. – Basile Starynkevitch Sep 17 '14 at 07:25
  • 1
    I don't think that there's an auxiliary program that takes into account what the programmer should have considered. As long as the memory is accessible, nothing can infer that an object should be deleted. – 101010 Sep 17 '14 at 07:25
  • 40two: I understand this is problematic. If I would have built this from scratch I probably would have had a better idea of what could be causing it. What I was thinking is that perhaps there is some program where you could filter and get like a list of all objects that have been alive for more than 60 min for example. If you the see loads of the same type with a long life span you could investigate that. – inquam Sep 17 '14 at 07:31
  • Boehm's GC can be used with a no-op as `free` or `delete` – Basile Starynkevitch Sep 17 '14 at 07:31
  • Have you tried valgrind or any other static code analysis tools? – GlGuru Sep 17 '14 at 07:38
  • GIGuru: I feel it would have a hard time grasping all the sub projects and resulting DLL's and be able to identify (or guess) what isn't deleted but I would have wanted deleted. I think something that could track how long objects have been alive and present that to me would be the best bet and then leave it up to me to manually use that information to determine where to look in more detail. Or can Valgrind do something like this? – inquam Sep 17 '14 at 07:45

2 Answers2

0

if you are using c++ and visual studio, I think this link is helpful. You can _CrtMemCheckpoint and CrtMemDumpStatistics when you need.

  • "Unfortunately" the project is written in Embarcadero RAD Studio 2010 (using C++ builder) and that limits things a bit. I wish many time it was using VS but sadly not :) – inquam Sep 17 '14 at 11:26
0

I ended up trying the evaluation version of Softwareverify's C++ Memory Validator.

It worked just like what I wanted and was able to provide a time line of memory allocations etc to allow me to identify what had been accumulating over time and how long it had been alive. Using that I was able to identify the problem and fix it.

inquam
  • 12,664
  • 15
  • 61
  • 101