确定Java程序中GDI对象数量的最佳方法是什么?

确定Java程序中GDI对象数量的最佳方法是什么?,java,windows,Java,Windows,我们的任务是定期检查Java进程在Windows机器上使用的GDI对象的数量。我们在使用第三方库时遇到了泄漏问题。当达到某个限制时,应用程序或多或少会崩溃。添加GDI对象列时,可以在Windows任务管理器中看到它们 因为我们没有找到一个现有的方法,所以我们最终使用它来访问user32.dll的 我们做了以下工作: 扩展了User32接口并添加了相应的方法 使用Native.loadLibrary()创建了扩展接口的实例 通过使用Kernel32.INSTANCE.GetCurrentProce

我们的任务是定期检查Java进程在Windows机器上使用的GDI对象的数量。我们在使用第三方库时遇到了泄漏问题。当达到某个限制时,应用程序或多或少会崩溃。添加GDI对象列时,可以在Windows任务管理器中看到它们

因为我们没有找到一个现有的方法,所以我们最终使用它来访问user32.dll的

我们做了以下工作:

  • 扩展了User32接口并添加了相应的方法
  • 使用Native.loadLibrary()创建了扩展接口的实例
  • 通过使用Kernel32.INSTANCE.GetCurrentProcess()和DWORD(0)调用实例的方法
  • 代码现在如下所示:

    public class GdiTester { 
    
        private static interface ExtendedUser32 extends User32 {
            /** 
             * Provides access to the user32.dll-API-Function GetGuiResources.
             * 
             * @param hProcess the process
             * @param uiFlags flags (e.g. 0 to get the number of GDI-objects)
             * @return result of the API-function call (e.g. the number of GDI-objects)
             */
            DWORD GetGuiResources(HANDLE hProcess, DWORD uiFlags);
        }
    
        private static ExtendedUser32 INSTANCE = Native.loadLibrary("user32", ExtendedUser32.class, W32APIOptions.DEFAULT_OPTIONS);
    
        public static void main(String[] args) {
            System.out.println("Number of GDI-objects: " + INSTANCE.GetGuiResources(Kernel32.INSTANCE.GetCurrentProcess(), new DWORD(0)).intValue());
        }
    }
    
    你知道其他(更好的)方法吗