On Thu, 14 Aug 2025 22:13:51 GMT, Sergey Bylokhov <s...@openjdk.org> wrote:
>> Remove finalize() from WInputMethod.java - it is used to free a native id. >> Also the reason dispose() didn't free it seems no longer relevant. >> Although I did see (when instrumenting) that dispose() was called when I >> disposed() the Frame referencing the IM, >> I don't know if I can be sure that is always done. So safest to add the >> Disposer in case it isn't. > > src/java.desktop/windows/classes/sun/awt/windows/WInputMethod.java line 165: > >> 163: @Override >> 164: public void dispose() { >> 165: disposerRecord.dispose(); > > The native dispose will call `ImmDestroyContext` which is specified as: >> However, before calling ImmDestroyContext, the application must remove the >> input context from any association with windows in the thread by using the >> [ImmAssociateContext](https://learn.microsoft.com/en-us/windows/desktop/api/imm/nf-imm-immassociatecontext) >> function. > > I did not check the code, but maybe we are calling `ImmAssociateContext` in > the wrong moment and have to postpone this "dispose" until all the object is > really unused? This seems to be done by a native method WInputMethod.disableNativeIME(..) - which sets the IME for the window to NULL. The native method is called from various places in WInputMethod. I can't see that dispose or finalize would do anything to ensure that is called, or introduce any timing issues either way. So if there's a problem it is un-related. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/26706#discussion_r2279695793