Early in my career I saw the aftermath of someone trying to deal with this problem. The solution they went with was to replace all allocations in the offending code with a custom allocator and then just throw the allocator away every so often
Was there any way for them to know when it was safe to do so? If not: Wouldn't stopping and restarting the program be better?
Plenty of cases fit the case, e.g. if it's some sort of server, you assign a separate allocator to each request and then purge it once the request is processed.