For some reasons my previous replies didn't get to the mailing list. The question is whether the pointer itself is on the stack or not. IIRC std::variant uses inline storage to store values, so a pointer that you keep in a std::variant would be on stack and would be found by stack scanning. std::vector, on the other hand, allocates an off-stack backing store that it allocates (and reallocates as the vector grows), so pointers kept in a std::vector would not be found by stack scanning.
If your tests pass, it's because the GC is finding your pointer somewhere else on the stack (e.g. left over from calling set_needle), but not in the vector. On Thursday, August 8, 2024 at 10:43:43 AM UTC+2 zcb...@gmail.com wrote: > To answer my own question, I wrote some tests: > > https://github.com/compilets/compilets/commit/d69722fb36260caa278843311cb043f5fe8a90d7 > > It seems that pointers stored in containers can be retained. > (It would be great if someone can verify this though.) > > On Thursday, August 8, 2024 at 9:11:33 AM UTC+9 Cheng wrote: > >> Cppgc does stack scanning so objects pointed by raw pointers on stack are >> not garbage collected: >> >> Object* ptr = MakeGarbageCollected<Object>(); // retained. >> >> But what if I put the pointer in a variant? >> >> std::variant<Object*, std::monostate> ptr = >> MakeGarbageCollected<Object>(); // retain? >> >> Or even in a vector? >> >> std::vector<Object*> ptrs = { MakeGarbageCollected<Object>() }; // retain? >> >> Will the object still be retained by the container of pointer on stack? >> > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/51079cea-d985-4195-b3ce-2086f6d3d562n%40googlegroups.com.