Closed bowen-xu closed 6 months ago
Hello,
A have a little note to your test code. You can write auto _tracked_node = tracked_node
instead auto _tracked_node = tracked_ptr<node>(tracked_node.get())
and _node.get()
is unnecessary.
Regarding deleting objects. The objects are available from the global pointer tracked_node
so they are not deleted. You can reset this pointer before the main function ends.
A have a little note to your test code. You can write auto _tracked_node = tracked_node instead auto _tracked_node = tracked_ptr
(tracked_node.get()) and _node.get() is unnecessary.
Got it.
Regarding deleting objects. The objects are available from the global pointer tracked_node so they are not deleted. You can reset this pointer before the main function ends.
Yes, I also found that. However, in some complex projects, we do not always remember which objects are global and needed to be reset manually. So I believe it woud be much better to make the program automatically delete all remaining objects when the gc is terminated.
@pebal Is there anything for me to further modify?
Hi @pebal, I found this repo very fantastic and try to use it for GC in C++.
It seems that after the main function exits, some tracked instances are not destroyed properly, because their deconstruction functions are not executed, though there are no memory leaks. I guess this is because when calling
terminate_collector()
, the instances are still reachable. Although I'm not familar with GC and how it workds, I tried to make the program remove all objects by setting themark
s as0
, and then call_remove_garbage()
again.Did I do it correctly? Please let me know if further modificaton is needed.
The code below is what I used for test.
Without
_remove_all()
, unexpectedly, some objects' deconstruction functions are not called.With the added code in this pr, the program's behavior becomes correct: