From: "kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core" Date: 2024-02-24T03:12:23+00:00 Subject: [ruby-core:116923] [Ruby master Feature#20290] Add API for C extensions to free memory Issue #20290 has been updated by kjtsanaktsidis (KJ Tsanaktsidis). Thanks Peter, that all sounds reasonable to me. > 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. Hm. I wonder if extension developers should themselves check if RUBY_FREE_AT_EXIT is set when deciding what to do in their `Destruct_` functions. Obviously they shouldn't be calling `getenv` and doing this parsing themselves, but maybe a parameter or function can be exposed where developers can do "important" cleanup unconditionally, but "optional" cleanup only if memory leak checking is on. I don't have a strong idea about what's "important" vs "optional" though. ---------------------------------------- Feature #20290: Add API for C extensions to free memory https://bugs.ruby-lang.org/issues/20290#change-106959 * 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_` that is called during shutdown when RUBY_FREE_AT_EXIT is enabled. This name mirrors the `Init_` API that already exists for extension initialization. However, unlike the `Init_` function, `Destruct_` is NOT mandatory for the C extension to implement so that we can preserve backwards compatibility. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/