2 ms·
If you correctly model ownership with RAII, which also enforces strong class invariants, and make sure all operations satisfy basic exception safety, then leaks
by mgaunard 5y ago
If you correctly model ownership with RAII, which also enforces strong class invariants, and make sure all operations satisfy basic exception safety, then leaks are not possible.
Those are the most elementary rules that one must follow when writing C++.
- bcrosby95 5y ago> If you correctly model ownership Doing something correctly is not a best practice though. If it were, we could just say "if you correctly manage memory". What happens when you mess up? What happens if you incorrectly model ownership with RAII? Or is it not really possible?
- deleted 5y ago[deleted]
- int_19h 5y agoObject graphs where there's no clear owner are not automatically "incorrect" - whatever they're modelling might be non-hierarchical itself - yet would result in a leak without a GC.
- mgaunard 5y agoThey are, sorry. There is no way to enforce basic guarantees without ownership.
- int_19h 5y agoGraphs where no single object is a clear owner happen all the time in real world, so I would argue that any object model that can't accurately model that is just not good enough. And what basic guarantees are not enforceable without ownership?