3 ms·
> A &g = *new A; > Note that this does not create a memory leak, since the pointer/reference is part of the root set. Can someone explain this to me? How woul
by spacechild1 3y ago
> A &g = *new A;
> Note that this does not create a memory leak, since the pointer/reference is part of the root set.
Can someone explain this to me? How would that not be a memory leak? What does 'root set' mean in this context?
- josephcsible 3y agoThat's not a memory leak (when done at top level) because it's reachable for the entire execution of the program. Memory is only leaked if it's still allocated once it's no longer reachable.
- spacechild1 3y agoMemcheck disagrees: https://developers.redhat.com/blog/2021/04/23/valgrind-memcheck-different-ways-to-lose-your-memory https://developers.redhat.com/blog/2021/04/23/valgrind-memch... Technically, this is still a memory leak, it's just considered less serious.