Manishearth / rust-gc

Simple tracing (mark and sweep) garbage collector for Rust
Mozilla Public License 2.0
972 stars 50 forks source link

Manual control over when GC runs #169

Open FeldrinH opened 1 year ago

FeldrinH commented 1 year ago

Currently it seems that GC can trigger a collection any time a new Gc is allocated. I would like to have manual control over when collection can happen. (I mean I want to prevent automatic collections during allocation from happening and instead manually call a function that checks the threshold and collects if there is too much allocated memory.)

Manishearth commented 1 year ago

I think this could be done behind a cfg/feature

stephanemagnenat commented 6 months ago

Yes that would be nice to have. For example in a scripting language used in a game, one would like to run the garbage collection in between frames (e.g., after the frame has been rendered and sent to the display). How big of a change would that feature be?

Manishearth commented 6 months ago

I don't think it would be that big. We already have a force_collect() function exposed. We can expose a second maybe_collect() that applies the threshold, and then have a way to disable the one place that collection is called automatically.