4 ms·
I'm not sure how I feel about GC in Rust. One of the useful things with Rust's ownership model is it forces good architectures. I feel like with a GC it's much
by vvanders 11y ago
I'm not sure how I feel about GC in Rust.
One of the useful things with Rust's ownership model is it forces good architectures. I feel like with a GC it's much easier to be "lazy" about who owns something which seems very counter to what I've found interesting and useful in Rust.
- spicyj 11y ago> Cases where one needs to maintain a complicated, dynamic graph are where a GC becomes useful. Similarly, if one is writing an interpreter for a GCd language, having a GC in Rust would simplify things a lot. > > Not to say that one should pervasively use a GC in Rust. Similar to Rc<T>, it’s best to use regular ownership-based memory management as much as possible, and sprinkle Rc/Gc in places where your code needs it. Hopefully people heed this advice. My guess is it will not be a problem because most example code (and all of the docs) will not use Gc pervasively.
- kibwen 11y agoNot only will the example code and docs never use Gc, there won't even be a Gc implementation in the stdlib. There are just too many potential variants of Gc (along with too little concrete demand) to ship any implementation by default.
- Manishearth 11y agoBesides what kibwen said, the docs don't even use Rc much, so we're safe on that front :)
- pcwalton 11y agoIt's very much opt-in: if you don't want it, it's easy (and the default) to not use it.
- dbaupp 11y agoUsing pervasive sharing in Rust is not the easiest route even with a perfect GC, e.g. one is forced to use types like RefCell and Cell anywhere that mutability is required, adding syntactic overhead, more restrictions (especially around threading), slight runtime overhead (mainly for the former; Cell "just" inhibits aliasing-based optimisations, while RefCell does that and stores & manipulates some extra integers) and runtime panics instead of compiletime errors, for RefCell.
- vvanders 11y agoThat's the thing though, every place I've seen pervasive sharing could be replaced my explicit ownership(including a clean mechanism for transferring ownership). Being explicit about who owns something makes it much harder to leak things by forgetting to clear references/etc.
- deleted 11y ago[deleted]
- Rusky 11y agoGarbage collection, or something like it, is very useful when implementing lock-free data structures, which are very important in systems programming. Typically they get implemented using some kind of RCU (there was even a post about doing that in Rust, recently), but it's good to have options when you're tuning performance at that level.
- steveklabnik 11y agohttps://news.ycombinator.com/item?id=10131429 https://news.ycombinator.com/item?id=10131429 :)
- eternalban 11y agoSometimes I feel rigorous thinking in software is a form of delusion. (Possibly related: one of the first thing I noted as a student (in architecture) was the fact of the 'beaten path' vs the ideal of the designated path.)
- Manishearth 11y agoAs I've mentioned in the post (anmd the readme, and in multiple discussions), rust-gc is not meant to be used pervasively :) Given that Rc is rarely/never used pervasively; I'm confident that this won't happen. For those intending to use GC pervasively: Every time you use Gc<bool>; I kill a kitten. Scratch that, I unleash an AbstractKittenKillerProxyFactory on the world :P Think of the kittens!
- amelius 11y agoOn the other hand, GC decouples reclamation from control flow. This means that, for instance, if you drop a reference to an object referencing a million other objects, that reclaiming does not necessarily have to happen instantaneously (i.e., blocking control flow). Instead, a GC can reclaim those objects in the background if desired (and if so designed).