Project

General

Profile

Actions

Feature #19333

open

Setting (Fiber Local|Thread Local|Fiber Storage) to nil should delete value in order to avoid memory leaks.

Added by ioquatix (Samuel Williams) almost 2 years ago. Updated 11 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:111789]

Description

As it stands, Fiber Locals, Thread Locals and Fiber Storage have no way of deleting key-value associations.

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.

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like1