Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to the Cleaner API #1702

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

otbutz
Copy link

@otbutz otbutz commented Jan 2, 2025

Fixes #1465

  • replaced the current implementation that relies on finalize() by using a Cleaner instead
  • the ResourceTracker no longer holds a reference to the resource, as the Cleaner API mandates that:

    The cleaning action is invoked only after the associated object becomes phantom reachable, so it is important that the object implementing the cleaning action does not hold references to the object.

  • a flag is now used to detect whether the nonDisposedReporter should be invoked.
  • the tracker is registered during init() to avoid false-negatives for resources throwing an exception in their constructor. e.g new Cursor(display, -100)

@otbutz otbutz marked this pull request as ready for review January 2, 2025 13:31
Copy link
Contributor

github-actions bot commented Jan 2, 2025

Test Results

   486 files  ±0     486 suites  ±0   9m 47s ⏱️ - 1m 1s
 4 306 tests ±0   4 293 ✅ ±0   13 💤 ±0  0 ❌ ±0 
16 408 runs  ±0  16 300 ✅ ±0  108 💤 ±0  0 ❌ ±0 

Results for commit 81ee856. ± Comparison against base commit 49fd6b0.

/**
* Invokes {@link ResourceTracker#run()} once the resource is eligible for GC
*/
private static final Cleaner cleaner = Cleaner.create();
Copy link
Author

Choose a reason for hiding this comment

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

We can pass our own ThreadFactory to have a nicer thread name, but IMHO this adds too much complexity for what it's worth.

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.

Avoid overriding finalize()
1 participant