News for hackers. Stuff that matters.
Re:D Language accepted for inclusion in GCC by yorwba on Wednesday June 21, 2017 @11:27AM (#14604601)
Rust has an opt-in garbage collector as a library (https://docs.rs/gc/). I don't know how good it is, though.
Re:D Language accepted for inclusion in GCC by Rusky on Wednesday June 21, 2017 @11:59AM (#14604908)
By that measure, so do C and C++.
Re:D Language accepted for inclusion in GCC by tcbawo on Wednesday June 21, 2017 @12:11PM (#14605036)
You could implement GC in C++ using RAII (although smart pointers get you a long way). AFAIK, automatic GC is not possible with C.
Re:D Language accepted for inclusion in GCC by antientropic on Wednesday June 21, 2017 @12:22PM (#14605171)
It absolutely is possible, via conservative GC: https://en.wikipedia.org/wiki/Boehm_garbage_collector
Re:D Language accepted for inclusion in GCC by timlyo on Wednesday June 21, 2017 @12:37PM (#14605340)
What's the use case for a garbage collector in rust?
Re:D Language accepted for inclusion in GCC by yorwba on Wednesday June 21, 2017 @01:38PM (#14606059)
If you have to share some data across your program and can't determine the lifetime at compilation time, you can't simply rely on the Rust compiler for memory management.

The next option is to use reference counting by wrapping your data in Rc/Arc (depending on whether you need atomicity or not).

But that can still leak memory if you have cyclic data structures and can't break the cycle with Weak pointers.

At this point, what you need is a garbage collector.