diff options
author | Peter Zhu <peter@peterzhu.ca> | 2023-07-24 14:21:50 -0400 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2023-08-25 09:01:21 -0400 |
commit | bfb395c620b811b4b3cb7d535d58721268af285d (patch) | |
tree | e32046e9dbff33ef2bdfe0bb8a51fb81613cbfbb /internal | |
parent | 633243958c1b19e7d934442e23ed3d7cc3d7691b (diff) |
Implement weak references in the GC
[Feature #19783]
This commit adds support for weak references in the GC through the
function `rb_gc_mark_weak`. Unlike strong references, weak references
does not mark the object, but rather lets the GC know that an object
refers to another one. If the child object is freed, the pointer from
the parent object is overwritten with `Qundef`.
Co-Authored-By: Jean Boussier <byroot@ruby-lang.org>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8113
Diffstat (limited to 'internal')
-rw-r--r-- | internal/gc.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/internal/gc.h b/internal/gc.h index 2934422474..7e0942a76a 100644 --- a/internal/gc.h +++ b/internal/gc.h @@ -235,6 +235,8 @@ VALUE rb_define_finalizer_no_check(VALUE obj, VALUE block); void rb_gc_mark_and_move(VALUE *ptr); +void rb_gc_mark_weak(VALUE *ptr); + #define rb_gc_mark_and_move_ptr(ptr) do { \ VALUE _obj = (VALUE)*(ptr); \ rb_gc_mark_and_move(&_obj); \ |