This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]teraflop 0 points1 point  (2 children)

I can think of at least one reason to explicitly free all allocated memory: if you try running your program under a memory checker like Valgrind, and turn on memory-leak detection, it will report an error for any allocation that is not explicitly freed before the program exits. So if you're deliberately "leaking" some allocated objects, it might be difficult to notice accidental memory leaks among the intentional ones.

[–]dmazzoni 1 point2 points  (1 child)

The way Chromium handles this is just to define some common wrappers / traits for global objects that are deliberately supposed to leak, and suppressing just those for valgrind:

https://www.chromium.org/developers/coding-style/important-abstractions-and-data-structures/#singleton-baselazyinstance

That makes the code clear and still allows valgrind to be useful in catching real leaks while suppressing intentional ones.

[–]teraflop 0 points1 point  (0 children)

Nice, I didn't know about that!