Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    Very thorough answer and abundantly useful. I have already begin other refactoring following the "compatibility" layer using the [deprecated] tag to make it more obvious that new code should not use that API anymore. Commented May 4, 2020 at 20:11
  • 1
    I would add a few things. Create and maintain a mental map of object ownership graph, and remember to validate and update whenever discrepancies are found. Also, use destructor instrumentation when creating your test suite. A crude way is to log a message whenever any destructor is entered. In other words, compare the timeline of destructor execution before, during, and after the code change. This will be needed to catch memory leaks (object leaks) and unintended consequences from altering the destruction sequence of multiple related objects. (...) Commented May 4, 2020 at 22:59
  • 1
    (...) Some commercial software testing frameworks may be able to perform runtime instrumentation (injecting binary instrumentation code into the application at runtime), and help detect memory leaks. Valgrind and Clang (ASan, UBSan) may help catch some use-after-free bugs. You may also improvise some creative ways of catching this type of bugs for some of your classes (e.g. putting magic numbers in fields or in an external table). Commented May 4, 2020 at 23:02
  • @rwong The code largely involves intense (multi-threaded) processing of large amounts of data and is not robust against speed reduction so unfortunately tools like Valgrind are not helpful since it requires too much overhead. I am not sure how much overhead is required for Asan and UBsan, but it is important that whatever is used doesn't slow things down. The idea of magic numbers sounds interesting -- e.g., put a magic value in a object on destruction and check for it upon destruction? Commented May 5, 2020 at 16:07