In the following example --- use a container to store a ref pointer ref ref Obj:
type
Obj = object
val: int
var container: pointer = alloc0(sizeof(pointer))
proc f() =
var obj1: ref Obj = new(Obj)
obj1.val = 100
(cast[ref ref Obj](container))[] = obj1
# GC_ref(obj) # still necessary? If not, can arc collect garbage correctly?
proc main() =
f()
GC_fullCollect()
var obj2 = new(Obj)
obj2.val = 1000
echo cast[ref ref Obj](container)[].val # Output: 100? 1000? unknown?
main()
When I use --gc:refc, the output is 1000, which indicates that GC_fullCollect() completely reclaims the memory of obj1. However, When I use --gc:arc, the output is 100. Does this mean that obj1 is automatically tracked by arc inside f()? Are GC_ref GC_unref necessary in this use case?