Project

General

Profile

Actions

Feature #21957

open

Introduce `Enumerable#close` to free internal resources.

Feature #21957: Introduce `Enumerable#close` to free internal resources.

Added by ioquatix (Samuel Williams) 4 days ago. Updated 3 days ago.

Status:
Open
Target version:
-
[ruby-core:125071]

Description

In some cases, Enumerable has substantial internal state (e.g. Fiber) related to enumeration. There is currently no way to clear up this state besides garbage collection, which means that we can accumulate considerable garbage before cleaning up, even if we know when the enumerable is no longer needed.

I'd like to introduce Enumerable#close which invalidates the enumerable, freeing internal resources. After which, most usage would result in Enumerable::ClosedError.

Updated by Eregon (Benoit Daloze) 3 days ago Actions #1 [ruby-core:125074]

+1

Leaking Fibers through an Enumerator is quite common and relying on the GC to clean that up is pretty brittle and it also adds significant complexity on the Ruby implementation (e.g. weakref to the Fiber object).

You're mentioning Enumerable here, but isn't it about Enumerator rather?

ioquatix (Samuel Williams) wrote:

After which, most usage would result in Enumerable::ClosedError.

Right, and that would work by simply having Enumerator#each for such Enumerators raise a Enumerator::ClosedError.

Actions

Also available in: PDF Atom