Skip to content

Use ObjectSpace::WeakKeyMap for level_override#136

Open
nevans wants to merge 1 commit intoruby:masterfrom
nevans:logger_override-weak_key_map
Open

Use ObjectSpace::WeakKeyMap for level_override#136
nevans wants to merge 1 commit intoruby:masterfrom
nevans:logger_override-weak_key_map

Conversation

@nevans
Copy link

@nevans nevans commented Oct 1, 2025

This allows fiber keys to be GCed and removed from the map. Otherwise, fibers that call #with_level create a memory leak if they are abandoned without running their ensure blocks.

Please note that Thread#kill is not the only way for a Fiber to be abandoned without running its ensure block. It's as simple as to_enum(:method_that_calls_with_level).next.


This is related to @byroot's comment here: #132 (comment)

This allows fiber keys to be GCed and removed from the map.  Otherwise,
fibers that call `#with_level` create a memory leak if they are killed
without running their ensure blocks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant