byroot (Jean Boussier) wrote in #note-24: > > I just don't think we should support this. > ... To be clear, we are aware we're doing really shady weird things to get a bit less overhead / a few more features, etc and we don't expect u...ivoanjo (Ivo Anjo)
> @ivoanjo (Ivo Anjo) I don't know if this would work, but what about using rb_postponed_job_trigger to delay adding the object into a WeakMap? (there would also probably need to be a temporary buffer used to mark the object until it is ...ivoanjo (Ivo Anjo)
> I'm fine with adding MOVEOBJ, it makes sense, but I don't think it's currently necessary. ObjectSpace.trace_object_allocations handles this by subscribing both to NEWOBJ and FREEOBJ and tracking the objects in its own hash table (subsc...ivoanjo (Ivo Anjo)
> That sounds like a use case for WeakRef or ObjectSpace::WeakMap. > ... In retrospect I was a bit confusing there -- The key missing bit is having something that's safe to use from `NEWOBJ` tracepoint, which is what `WeakRef` and `Weak...ivoanjo (Ivo Anjo)
Having `MOVEDOBJ` would be very useful for being able to use the address as identity + I think it may come in handy for caches -- I think it would solve the "a) Be able to identify or reference object without preventing its GC, even if t...ivoanjo (Ivo Anjo)
> rb_gc_mark_weak can be an option, another may be to have a mechanism to prevent compaction, so you can simply rely on addresses. Maybe, yeah! Effectively the two requirements I believe are: a) Be able to identify or reference obj...ivoanjo (Ivo Anjo)
Thanks for the hint, Peter! I had not spotted https://bugs.ruby-lang.org/issues/21084 :) Based on your notes it looks like exposing a `rb_gc_declare_weak_references` is a much better choice 👍ivoanjo (Ivo Anjo)
In https://bugs.ruby-lang.org/issues/21710 it came up that 1. On top of [deprecating _id2ref](https://bugs.ruby-lang.org/issues/15408) on Ruby 4.0, [it's a bad idea to be using object_id from the NEWOBJ tracepoint](https://bugs.ruby-l...ivoanjo (Ivo Anjo)
> And since rb_gc_mark_weak isn't public API, there's no decent way to have weakrefs in a C extensions (except if you assume/enforce no compaction, then you can use just the address). Ahhhhh I totally had missed that one. Ever since I...ivoanjo (Ivo Anjo)