A few years ago, before auto_ptr , I wrote my own class of smart pointers, which we widely used in our code base. Of course, this was a complete push for errors.
I had exactly the same problem. Although I canโt show you the actual code that I used to identify call sites that experienced resource leaks (since the code no longer exists), I can tell you what I did.
The first thing I wrote was the #define > SHUDDER <macro, similar to the one I set out here , which I could use instead of new to highlight my objects. The macro sent additional parameters to the smart pointer, indicating the file number and call site number. A smart pointer will save that.
Then I replaced the global new my macro when I cast the #defines magic spell that included this feature. Obviously, this should be disabled in all Releaseasse builds and only used in Debug builds when you are really debugging it.
Then I run my program until I get to the point where I would like to see all the call sites. I would execute the dump_call_sites() method on a smart pointer that dumped the static vector lines of the call site lines to standard output. Thus, the problem found, I would return all these magic spells to disable all this pokus hokus.
This is really code encryption. This is far from elegant, and he introduces his own set of problems into it. But along with debugging printf it has its place. If you donโt want or cannot go downloading your Rational Purify or Bounds Checker product, this can help you quickly identify where the leaks are coming from.
source share