Skip to content

Commit 971ea23

Browse files
committed
8362289: [macOS] Remove finalize method in JRSUIControls.java
Reviewed-by: bchristi, serb
1 parent 4e53a9d commit 971ea23

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
import java.nio.*;
2929
import java.util.*;
30+
import sun.java2d.Disposer;
31+
import sun.java2d.DisposerRecord;
3032

3133
import apple.laf.JRSUIConstants.*;
3234

@@ -91,7 +93,8 @@ private static ThreadLocalByteBuffer getThreadLocalBuffer() {
9193

9294
private final HashMap<Key, DoubleValue> nativeMap;
9395
private final HashMap<Key, DoubleValue> changes;
94-
private long cfDictionaryPtr;
96+
private final long cfDictionaryPtr;
97+
private final Object disposerReferent = new Object();
9598

9699
private long priorEncodedProperties;
97100
private long currentEncodedProperties;
@@ -101,6 +104,7 @@ public JRSUIControl(final boolean flipped){
101104
this.flipped = flipped;
102105
cfDictionaryPtr = getCFDictionary(flipped);
103106
if (cfDictionaryPtr == 0) throw new RuntimeException("Unable to create native representation");
107+
Disposer.addRecord(disposerReferent, new JRSUIControlDisposerRecord(cfDictionaryPtr));
104108
nativeMap = new HashMap<Key, DoubleValue>();
105109
changes = new HashMap<Key, DoubleValue>();
106110
}
@@ -109,17 +113,25 @@ public JRSUIControl(final boolean flipped){
109113
flipped = other.flipped;
110114
cfDictionaryPtr = getCFDictionary(flipped);
111115
if (cfDictionaryPtr == 0) throw new RuntimeException("Unable to create native representation");
116+
Disposer.addRecord(disposerReferent, new JRSUIControlDisposerRecord(cfDictionaryPtr));
112117
nativeMap = new HashMap<Key, DoubleValue>();
113118
changes = new HashMap<Key, DoubleValue>(other.nativeMap);
114119
changes.putAll(other.changes);
115120
}
116121

117-
@Override
118-
@SuppressWarnings("removal")
119-
protected synchronized void finalize() throws Throwable {
120-
if (cfDictionaryPtr == 0) return;
121-
disposeCFDictionary(cfDictionaryPtr);
122-
cfDictionaryPtr = 0;
122+
private static class JRSUIControlDisposerRecord implements DisposerRecord {
123+
124+
private final long cfDictionaryPtr;
125+
JRSUIControlDisposerRecord(long ptr) {
126+
cfDictionaryPtr = ptr;
127+
}
128+
129+
public void dispose() {
130+
try {
131+
disposeCFDictionary(cfDictionaryPtr);
132+
} catch (Throwable t) {
133+
}
134+
}
123135
}
124136

125137

0 commit comments

Comments
 (0)