quark-zju / gcmodule

Garbage collection for Rust inspired by CPython's gcmodule
MIT License
20 stars 5 forks source link

Ability to disable garbage collection on exit #15

Closed CertainLach closed 2 years ago

CertainLach commented 2 years ago

While this toggle isn't useful in general (because you can always call forget(space)), it is useful in thread-local case, because destructors for TLS entries are ran, and this isn't needed in case of CLI apps, where it delays shutdown

quark-zju commented 2 years ago

Does libc::_exit (instead of std::process::exit) work for your use-case?

CertainLach commented 2 years ago

libc::exit still causes thread local destruction, thus slowing down shutdown

quark-zju commented 2 years ago

Note libc has 2 functions: exit and _exit. What I suggested is _exit with an underscore prefix.

Regarding on the API. How do you think about:

  1. ObjectSpace::leak(&mut self). It re-initializes its linked list. The name leak is shorter, more explicit and seems to be more generic (does not couple with Drop).
  2. Expose the thread-local ObjectSpace via with_thread_object_space(f: impl FnOnce(&mut ObjectSpace)). This allows one to call the leak API. In your case, you can call it before exit (if you don't want to use _exit).
CertainLach commented 2 years ago

I love idea of leak method, it definitely looks more clear than current collect_on_drop field approach