Sitelet https://github.com/javaevolved/javaevolved.github.io/pull/196
Skip to content

Add deterministic resource cleanup pattern - #196

Merged
brunoborges merged 1 commit into
mainfrom
brunoborges-pattern-finalizers-deterministic-cleanup
Aug 26, 2026
Merged

Add deterministic resource cleanup pattern#196
brunoborges merged 1 commit into
mainfrom
brunoborges-pattern-finalizers-deterministic-cleanup

Conversation

@brunoborges

Copy link
Copy Markdown
Member

Finalization is deprecated for removal and cannot guarantee prompt or ordered cleanup. This adds a migration pattern showing deterministic resource management with AutoCloseable, while retaining Cleaner only as a defensive fallback for leaked resources.

The modern example isolates cleanup state in a static Runnable so the cleaner action does not retain the registered resource. It also adds a Java 25 proof and inserts the pattern next to the existing try-with-resources entry in the I/O navigation chain.

Fixes: #173

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@brunoborges
brunoborges merged commit 4c86b21 into main Aug 26, 2026
2 checks passed
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.

[Pattern] Finalizers to deterministic resource cleanup

1 participant