diff --git a/native/MacTouchBar/src/TouchBar.m b/native/MacTouchBar/src/TouchBar.m index b9d40a92f21a..e6813ba77a32 100644 --- a/native/MacTouchBar/src/TouchBar.m +++ b/native/MacTouchBar/src/TouchBar.m @@ -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(); }); } } diff --git a/platform/platform-tests/testSrc/com/intellij/ui/mac/touchbar/TouchbarTest.java b/platform/platform-tests/testSrc/com/intellij/ui/mac/touchbar/TouchbarTest.java index 207a4e037018..e39baed10cd0 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/mac/touchbar/TouchbarTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ui/mac/touchbar/TouchbarTest.java @@ -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() {