Re:A Garbage Collector for C and C++
by moonchrome on Friday July 10, 2015 @04:35AM
(#9862865)
>But there is no reason that the RAII pattern couldn't be completely orthogonal to memory management
GC + destructors = very very messy even in languages built with GC in mind, kentonv described the whole non deterministic finalizers nicely but there are also other problems see here :
http://ericlippert.com/2015/05/18/when-everything-you-know-i...
Re:A Garbage Collector for C and C++
by ExpiredLink on Friday July 10, 2015 @04:16AM
(#9862817)
Could. A hypothetical new language could be created to facilitate whole-program escape analysis and thus completely avoid both GC and manual memory (resource) management.
This sounds awfully like the ownership concepts used in Rust...
You could do that, but if you are using RAII, then GC has lost a lot of its value. It is incorrect to access an object after its destructor has executed, so you might as well release its heap resources then and ditch the whole complicated GC.
I suppose in theory you could use GC just for objects that (transitively) don't hold any non-heap resources. But that gets a little weird as if you ever device that you need to stick a non-heap resource in there, suddenly all your code needs to change. (Of course, this is already generally the case in GC languages...)
But there is no reason that the RAII pattern couldn't be completely orthogonal to memory management.