IDEA-272894: fix object release

strong property doesn't clear automatically

GitOrigin-RevId: f55f6d24690c1739de5c3814d877d9b51d18480c
This commit is contained in:
Artem Bochkarev
2021-07-05 06:49:09 +00:00
committed by intellij-monorepo-bot
parent 0e695adfdb
commit ce06ff91ee
2 changed files with 35 additions and 6 deletions
+7 -2
View File
@@ -85,11 +85,16 @@ void setPrincipal(id tbobj, const char * uid) {
__used
void releaseNativePeer(id tbobj) {
void (^doRelease)() = ^{
if ([tbobj isKindOfClass:[NSCustomTouchBarItem class]])
((NSCustomTouchBarItem *)tbobj).view = nil;
[tbobj release];
};
if ([NSThread isMainThread]) {
[tbobj release];
doRelease();
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[tbobj release];
doRelease();
});
}
}
@@ -2,6 +2,7 @@
package com.intellij.ui.mac.touchbar;
import com.intellij.openapi.util.IconLoader;
import com.intellij.ui.mac.foundation.ID;
import javax.swing.*;
import java.util.Collection;
@@ -18,14 +19,37 @@ public class TouchbarTest {
private static void _createFrame() {
NST.loadLibraryImpl();
final TouchBar testTB = _createTestScrubberTouchbar();
testTB.selectVisibleItemsToShow();
testTB.setTo(null);
final JFrame f = new JFrame();
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.setBounds(0, 0, 500, 110);
f.setVisible(true);
new Thread(()-> {
int c = 1;
while (--c >= 0) {
final TouchBar testTB = _createSimpleTestTouchbar();
testTB.selectVisibleItemsToShow();
testTB.setTo(null);
try {
Thread.sleep(2000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
NST.setTouchBar(null, ID.NIL);
testTB.release();
}
}).start();
}
private static TouchBar _createSimpleTestTouchbar() {
final int configPopoverWidth = 143;
final TouchBar testTB = new TouchBar("test_simple");
testTB.addButton().setText("butt").setAction(createPrintTextCallback("pressed button"), false);
return testTB;
}
private static TouchBar _createTestButtonsTouchbar() {