Project

General

Profile

Actions

Bug #12175

closed

rb_gc_mark prevents the value from being garbage collected if called outside of a GC cycle

Added by murgatroid99 (Michael Lumish) almost 9 years ago. Updated over 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
[ruby-core:74310]

Description

I had some code that called rb_gc_mark in an initializer function instead of in the corresponding mark function, and the value never got garbage collected, causing a memory leak. This seems like an easy mistake to make, and there does not appear to be a corresponding function to make the value eligible for garbage collection again.

If the intention of the API when calling it in that situation is to make it a root object, then there should be a function to remove that indicator once the object no longer needs to be live. And if the intention is for the function to only work properly during a GC mark phase, then it should be an error to call it at any other time.

Updated by shyouhei (Shyouhei Urabe) almost 9 years ago

I bet rb_gc_mark is not intended to run outside of GC. It is easy to check in-memory flag but costs extra few hundred cycles per function call. A debatable drawback.

Actions #2

Updated by jeremyevans0 (Jeremy Evans) over 5 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0