SWT - 如何调试“不再有句柄”
有时我会被“org.eclipse.swt.SWTError:没有更多句柄”所困扰。我已经知道像 GDIView 这样的工具来观察分配的句柄数量,但现在我想知道是否有更好的方法来做到这一点。
有可用的工具吗?也许在创建句柄时记录所有堆栈跟踪?其中显示两个调用点之间的新句柄?
问候, Daniel
PS:添加了 windows 标签,因为开发主要发生在 Windows 上,并且仅 Windows 工具就足够了。
from time to time I am haunted by the "org.eclipse.swt.SWTError: No more handles". I already know tools like GDIView, to watch the number of handles allocated, but now I wonder if there is a better way to do this.
Is there a tool available? Maybe one that logs all stacktraces when handles are created? And which shows the new handles between two invocation points?
Regards,
Daniel
PS: Added the windows tag because dev occures mostly on windows and a windows only tool would be good enough.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现了 Sleak,这是一个调试 SWT 资源的好工具!强烈推荐给有同样问题的每个人。甚至还显示图像资源的图像!
I found out about Sleak, a great tool to debug SWT resources! Highly recommended for everyone with the same problems. Even shows the images for image resources!
对我来说,问题只是 new Shell() 被调用得太频繁。将 shell 存储为静态成员并重用它会有所帮助。因此,在应用像 Sleak 这样的工具之前,其他人可能想要对“new Shell”进行全文搜索,并检查它们是否有相同的简单原因。
For me the issue was simply that new Shell() has been called too often. Storing the shell as static member and reusing it helped. Therefore, before applying a tool like Sleak, others might want to do a full text search for "new Shell" and check that they don't have the same simple cause.
Sleak 似乎非常过时,我没有让它工作。
最终这也会对某人有所帮助。在 ui 代码的早期添加以下代码:
关闭/处置应用程序时的输出:
还会输出一个包含堆栈跟踪的列表,其中包含分配资源的位置。
有关更多详细信息,请参阅设备类源代码: https://github.com/eclipse-platform/eclipse.platform.swt/blob/7479681ce2cd75b1adb10220d061d83e4f83e2cd/bundles/org.eclipse.swt/Eclipse %20SWT/cocoa/org/eclipse/swt/graphics/Device.java
Sleak seems to be very outdated and I did not get it working.
Eventually this will also help someone. Add the following code early in your ui code:
Output on close/dispose of the application:
Also a list with stacktraces is outputed with places where resources was allocated.
See Device class source code for further details: https://github.com/eclipse-platform/eclipse.platform.swt/blob/7479681ce2cd75b1adb10220d061d83e4f83e2cd/bundles/org.eclipse.swt/Eclipse%20SWT/cocoa/org/eclipse/swt/graphics/Device.java