1

When working on a big codebase, it's hard to keep track of where an object is being destroyed, especially if you didn't write the code yourself. Is there a way to search through a project and find all places where a variable of a certain type is being destroyed (i.e. having its destructor called)? Looking through each Free in the codebase is not feasible for me.

KleberPF
  • 120
  • 1
  • 7
  • 3
    Using the debugger, putting a breakpoint in the object's destructor and looking at the call stack, you'll known where the object is destroyed. – fpiette Oct 11 '22 at 19:05
  • Sadly my codebase is complex enough where I can't just run it and expect to go through all paths of it. I needed some sort of static analysis that looks if `Free` is being called on an object of type X. – KleberPF Oct 11 '22 at 21:00
  • 1
    KleberPF: That is almost impossible to do statically, because the source code may contain `X.Free` where `X` is an expression of type `TObject`. The actual object that `X` points to may be a `TBitmap` the first Monday of every odd month, and a `TEvent` on all other days. (Or it may depend on the location of the user's mouse cursor, or the rate of change of its horizontal component.) – Andreas Rejbrand Oct 11 '22 at 21:03
  • Under the `Search` menu in the IDE, you can use `Find in Files`. There you can specify what to search for and where to search – Eirik A. Oct 11 '22 at 23:27
  • @AndreasRejbrand I see, but would there be a way to find all the "normal" cases (where `Free` is being called on a variable of type `X`)? – KleberPF Oct 12 '22 at 20:05
  • @KleberPF: Yes, but that would obviously only find a small fraction of all possible cases. Because Delphi is an object-oriented programming language, so things like `var X: TFruit; x := TApple.Create;` are not only perfectly valid, but also idiomatic and *very* common. You use that kind of things everywhere! – Andreas Rejbrand Oct 12 '22 at 20:15

1 Answers1

0

If you're trying to find memory leaks, consider checking FastMM5, here: FastMM5