Issue #19333 has been updated by Eregon (Benoit Daloze).
There is also `Thread#key?` for Fiber locals, so not just `thread_variable?`.
Above I am talking more about the performance issue than the semantic incompatibility.
Doing delete+insert is more expensive than set+set, and even much more so if Fiber/Thread
locals are implemented with Shape (which is already the case of TruffleRuby, so not
theoretical).
----------------------------------------
Feature #19333: Setting (Fiber Local|Thread Local|Fiber Storage) to nil should delete
value in order to avoid memory leaks.
https://bugs.ruby-lang.org/issues/19333#change-101302
* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
----------------------------------------
As it stands, Fiber Locals, Thread Locals and Fiber Storage have no way of deleting
key-value associations.
```ruby
100.times do |i|
name = :"variable-#{i}"
Thread.current[name] = 10
end
```
Because of this, dynamically generated associations can leak over time. This is worse for
things like Threads that might be pooled (or maybe an argument against user-space
pooling).
In any case, having a way to delete those associations would allow application code to at
least delete the associations when they no longer make sense.
I propose that assigning `nil` to "locals" or "storage" should
effectively delete them.
e.g.
```ruby
100.times do |i|
name = :"variable-#{i}"
Thread.current[name] = 10
Thread.current[name] = nil # delete association
end
```
A more invasive alternative would be to define new interfaces like `Thread::Local`,
`Fiber::Local` and `Fiber::Storage::Local` (or something) which correctly clean up on GC.
--
https://bugs.ruby-lang.org/