
Issue #20290 has been updated by kou (Kouhei Sutou). mdalessio (Mike Dalessio) wrote in #note-3:
I would consider calling libxml2's `xmlCleanupParser` from Nokogiri's `Destruct` function if this feature is made available, because libxml2 keeps some long-lived global state (like character encoding handlers) that might not otherwise be freed.
If we want to use this feature for general bound library destruction, it's better that this feature is invoked even when `RUBY_FREE_AT_EXIT` isn't `1`. ---------------------------------------- Feature #20290: Add API for C extensions to free memory https://bugs.ruby-lang.org/issues/20290#change-106957 * Author: peterzhu2118 (Peter Zhu) * Status: Open ---------------------------------------- GitHub PR: https://github.com/ruby/ruby/pull/10055 Ticket #19993 added the new feature RUBY_FREE_AT_EXIT, which frees memory in Ruby at shutdown. This allowed tools like Valgrind, ASAN, and macOS leaks to find memory leaks in Ruby without a large number of false-positives outputted. However, this feature is not complete for C extensions, as they may also need to free their memory and there was no way to do so. This means that C extensions might not be able to directly use tools like Valgrind, ASAN, or macOS leaks to find memory leaks. This ticket proposes an API for C extensions to free memory by defining a function called `Destruct_<extension name>` that is called during shutdown when RUBY_FREE_AT_EXIT is enabled. This name mirrors the `Init_<extension name>` API that already exists for extension initialization. However, unlike the `Init_<extension name>` function, `Destruct_<extension name>` is NOT mandatory for the C extension to implement so that we can preserve backwards compatibility. -- https://bugs.ruby-lang.org/