Troubleshooting Memory Leak in JInput: Windows Not Getting Destroyed Properly

122 Views Asked by At

Background

I'm working on implementing controller hot swapping in JInput and have encountered a memory leak. I've made some progress on the Java side, which is documented in this PR, but there seems to be a lingering problem on the native C side, specifically regarding window creation and destruction.

The full background of the issue can be found here.

Issue Description

In the JInput library, joystick input on Windows involves creating and destroying windows. This process is handled by the native C code, which can be found here. The problem arises when I attempt to destroy these windows using DestroyWindow. Even after calling this function, the hidden windows continue to appear in tools such as WinLister and Spy++ and accumulate in memory causing a resource leak.

What I've Tried

  1. I've attempted to process all remaining messages for the windows before destroying them.
  2. I've made sure that both creation and destruction are performed by the same thread.
  3. I've checked the return value of DestroyWindow and verified that it is not reporting any errors by calling GetLastError.

An interesting observation is that when I attempt to call DestroyWindow again with the same handle, it returns error code 1400, indicating an invalid handle.

0

There are 0 best solutions below