From bfb395c620b811b4b3cb7d535d58721268af285d Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 24 Jul 2023 14:21:50 -0400 Subject: 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 --- internal/gc.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'internal') 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); \ -- cgit v1.2.3