Skip to content

8362557: [macOS] Remove CFont.finalize() #26373

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/java.desktop/macosx/classes/sun/font/CFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import sun.java2d.Disposer;
import sun.java2d.DisposerRecord;

// Right now this class is final to avoid a problem with native code.
// For some reason the JNI IsInstanceOf was not working correctly
Expand Down Expand Up @@ -98,6 +100,7 @@ private static native long createNativeFont(final String nativeFontName,
private boolean isFakeItalic;
private String nativeFontName;
private long nativeFontPtr;
private final Object disposerReferent = new Object();

private native float getWidthNative(final long nativeFontPtr);
private native float getWeightNative(final long nativeFontPtr);
Expand Down Expand Up @@ -194,6 +197,7 @@ public CFont createItalicVariant() {
protected synchronized long getNativeFontPtr() {
if (nativeFontPtr == 0L) {
nativeFontPtr = createNativeFont(nativeFontName, style);
Disposer.addRecord(disposerReferent, new CFontDisposerRecord(nativeFontPtr));
}
return nativeFontPtr;
}
Expand Down Expand Up @@ -256,13 +260,17 @@ public CompositeFont getCompositeFont2D() {
return compFont;
}

@Override
@SuppressWarnings("removal")
protected synchronized void finalize() {
if (nativeFontPtr != 0) {
private static class CFontDisposerRecord implements DisposerRecord {

private final long nativeFontPtr;

CFontDisposerRecord(long ptr) {
nativeFontPtr = ptr;
}

public void dispose() {
disposeNativeFont(nativeFontPtr);
}
nativeFontPtr = 0;
}

@Override
Expand Down