3 ms·
Generic code with all my objects cleaning up after themselves. Are you sure they really cleaned up after themselves, and you don't have a subtle memory leak wa
by gcv 17y ago
Generic code with all my objects cleaning up after themselves.
Are you sure they really cleaned up after themselves, and you don't have a subtle memory leak waiting to happen because of some unnoticed and rare and disastrous problem with the order in which your destructors get called? :)
- thras 17y agoGenerally not a problem if you don't use much multi-inheritance. Making your objects exception-safe will have lots of benefits -- and it's exceptions that are far more likely to be causing leaks in your code than destructor-order issues. Your mileage may vary. Then again, I don't mean to trivialize the issue. It can be a real problem. But can you suggest a language that will prevent 100% of subtle memory leaks? I can't think of any. Hell, if you're using Ruby with a pre-1.8 VM, you don't even need to roll your own leaks.
- sorbits 17y agoWith proper overloads you can easily track your memory usage or even which instances are leaked. So yes, C++ is low-level (it does after all include C), but it has features to abstract away tedious details — this allows higher level programming but being in control of how the abstractions are implemented, as there are many performance trade-offs in choosing (implementation of) abstractions, and that is what makes C++ such nice language for software where performance is important.