Skip to content

Commit 3acdba3

Browse files
committed
8362557: [macOS] Remove CFont.finalize()
Reviewed-by: serb, psadhukhan, kizune
1 parent 523993e commit 3acdba3

File tree

1 file changed

+13
-5
lines changed
  • src/java.desktop/macosx/classes/sun/font

1 file changed

+13
-5
lines changed

src/java.desktop/macosx/classes/sun/font/CFont.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.awt.geom.Point2D;
3333
import java.awt.geom.Rectangle2D;
3434
import java.util.ArrayList;
35+
import sun.java2d.Disposer;
36+
import sun.java2d.DisposerRecord;
3537

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

102105
private native float getWidthNative(final long nativeFontPtr);
103106
private native float getWeightNative(final long nativeFontPtr);
@@ -194,6 +197,7 @@ public CFont createItalicVariant() {
194197
protected synchronized long getNativeFontPtr() {
195198
if (nativeFontPtr == 0L) {
196199
nativeFontPtr = createNativeFont(nativeFontName, style);
200+
Disposer.addRecord(disposerReferent, new CFontDisposerRecord(nativeFontPtr));
197201
}
198202
return nativeFontPtr;
199203
}
@@ -256,13 +260,17 @@ public CompositeFont getCompositeFont2D() {
256260
return compFont;
257261
}
258262

259-
@Override
260-
@SuppressWarnings("removal")
261-
protected synchronized void finalize() {
262-
if (nativeFontPtr != 0) {
263+
private static class CFontDisposerRecord implements DisposerRecord {
264+
265+
private final long nativeFontPtr;
266+
267+
CFontDisposerRecord(long ptr) {
268+
nativeFontPtr = ptr;
269+
}
270+
271+
public void dispose() {
263272
disposeNativeFont(nativeFontPtr);
264273
}
265-
nativeFontPtr = 0;
266274
}
267275

268276
@Override

0 commit comments

Comments
 (0)