On Mon, 23 Mar 2026 08:56:58 GMT, Jayathirth D V <[email protected]> wrote:

>> modules/javafx.graphics/src/main/native-glass/mac/GlassApplication.m line 
>> 1364:
>> 
>>> 1362:     dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, 
>>> (int64_t)(NSEC_PER_SEC)); // 1 second timeout
>>> 1363: 
>>> 1364:     dispatch_retain(semaphore);
>> 
>> This fix looks incorrect. When the semaphore is created it will have a 
>> retain count of 1. This line bumps the retain count to two. After 
>> dispatch_semaphore_signal the semaphore is released and the retain count 
>> will go back to 1. So the leak will still be present.
>> 
>> The pattern used in AWT is to call dispatch_retain once and dispatch_release 
>> twice, once after dispatch_semaphore_signal and again after 
>> dispatch_semaphore_wait. That's a bit excessive (all one really needs is a 
>> single call to dispatch_release after dispatch_semaphore_wait) but it's 
>> probably not a bad idea to follow AWT's lead here.
>
> Yes, this addition of new retain & release will continue to cause leak of 
> semaphore. In case of timeout the ref count of semaphore will be 2 and 
> without timeout it will be ref count will be 1.
> 
> There should be double release as in JDK's 
> src/java.desktop/macosx/native/libawt_lwawt/awt/CDesktopPeer.m or just have 
> single dispatch_release after wait. Also we can print the ref count of 
> semaphore and check whether the value just before final release.

Yes, I lost the second release after wait at some point. I will fix it shortly.

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/2110#discussion_r2974009530

Reply via email to