Skip to content

Simplify cleanup logic of ForestWrapper#118

Open
vchuravy wants to merge 2 commits into
DLR-AMR:mainfrom
vchuravy:vc/simplify_cleanup
Open

Simplify cleanup logic of ForestWrapper#118
vchuravy wants to merge 2 commits into
DLR-AMR:mainfrom
vchuravy:vc/simplify_cleanup

Conversation

@vchuravy
Copy link
Copy Markdown

@vchuravy vchuravy commented May 4, 2026

The ForestWrapper already assumed that it is going to be called
in-order, otherwise the same unique_id would have been associated with
different forests. So instead of using a dictonary we can use a FIFO.

Additionally we added ourself unconditionally to the
T8CODE_OBJECT_TRACKER thus ensuring that GC would never free those
objects, relying on clean_up to finalize the objects at the end.

vchuravy added 2 commits May 4, 2026 17:11
The ForestWrapper already assumed that it is going to be called
in-order, otherwise the same `unique_id` would have been associated with
different forests. So instead of using a dictonary we can use a FIFO.

Additionally we added ourself unconditionally to the
T8CODE_OBJECT_TRACKER thus ensuring that GC would never free those
objects, relying on `clean_up` to finalize the objects at the end.
Comment thread src/T8code.jl
Comment on lines -171 to -172
In serial mode the wrapper and in consequence the t8code forest
can be finalized immediately whenever Julia's garbage collector sees fit.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement was not true, since the object was always preserved in the T8Code_OBJECT_TRACKER

Comment thread src/T8code.jl
delete!(T8CODE_OBJECT_TRACKER, unique_id)
# arrays.
t8_forest_unref(Ref(w.pointer))
w.pointer = C_NULL
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the pointer to null, to avoid a double free through the same object

@JoshuaLampert
Copy link
Copy Markdown
Collaborator

Can one of you review this PR, @benegee, @spenke91?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants