什么是最大值内存可用于应用程序? (没有更多句柄错误)

时间:2021-08-08 00:09:05

In an Eclipse RCP application I am trying to open many editors. It is a basically a tree with lot of nodes each of which opens an editor. When I open in access of 150 to 200 editors and try to open an editor for next treenode it doesn't open. Eclipse console shows "org.eclipse.swt.SWTError: No more handles". However if I close a few of already opened editors I am able to open as many new treenode editors.

在Eclipse RCP应用程序中,我试图打开许多编辑器。它基本上是一棵树,有很多节点,每个节点都打开一个编辑器。当我打开访问150到200个编辑器并尝试打开下一个treenode的编辑器时,它无法打开。 Eclipse控制台显示“org.eclipse.swt.SWTError:不再处理”。但是,如果我关闭一些已经打开的编辑器,我可以打开尽可能多的新treenode编辑器。

I monitored the memory usage for javaw.exe; memory grows on opening of each editor but number of handles remain constant after a certain MAX. javaw.exe consumes around 120,000K when the error happens. The total memory consumed by all applications during error is 700,000K. And if I try to open a few more applications like IE it either doesn’t open or opens with lesser UI features due to shortage of system memory. And all this in spite of having 2GB RAM!

我监视了javaw.exe的内存使用情况;在打开每个编辑器时内存会增加,但在某个MAX之后句柄的数量保持不变。发生错误时,javaw.exe消耗大约120,000K。错误期间所有应用程序消耗的总内存为700,000K。如果我尝试打开一些像IE这样的应用程序,由于系统内存不足,它或者打开或打开时UI功能较少。尽管有2GB RAM,所有这一切!

I also tried by increasing vmargs in eclipse memory settings but it wasn’t of much help either.

我也试过在eclipse内存设置中增加vmargs,但它也没有多大帮助。

a) Is there a memory leak in my code? I don’t see it as handles remain constant after a certain MAX. As I understand, as editors are open, the SWT controls on it are not disposed until they are closed.

a)我的代码中是否有内存泄漏?我没有看到它,因为句柄在某个MAX之后保持不变。据我所知,当编辑器处于打开状态时,它上面的SWT控件在关闭之前不会被释放。

b) Whats the max. memory that can be used up by applications? As my RAM is 2GB and I see that my overall memory to all processes should be way better than 700,000K which I think is around 680MB.

b)什么是最大值可以被应用程序使用的内存?因为我的RAM是2GB,我看到我对所有进程的整体内存应该比700,000K好,我认为大约是680MB。

4 个解决方案

#1


a) Try Sleak. It can find GDI-leaks in your SWT-application

a)尝试Sleak。它可以在您的SWT应用程序中找到GDI泄漏

b) You can try to change the maximum GDI handles or User object in the registry. See here and here more information.

b)您可以尝试更改注册表中的最大GDI句柄或User对象。在这里和这里了解更多信息。

You also might want to try to create a vitual tree so that only tree nodes that are shown are created.

您还可能希望尝试创建一个虚拟树,以便只创建显示的树节点。

#2


I cannot answer specifically your question, but it seems to me you are running into the maximum limit of open files a process can have at any time (judging from the "handles" term, which often refers to open files, much like file descriptors in Unix). It would be a matter of operating-system-level user permissions/capabilities then. The allowed number of open files has nothing to do with memory size.

我无法专门回答你的问题,但在我看来,你正在遇到进程可以随时拥有的打开文件的最大限制(从“句柄”术语来判断,这通常指的是打开文件,就像文件描述符一样) Unix的)。这将是操作系统级用户权限/功能的问题。允许的打开文件数与内存大小无关。

#3


Handles refers to file handles (open file references) and is controlled by the operating system. It's not typically a user changed setting because keeping lots of file handles open indefinitely hogs OS resources.

句柄指文件句柄(打开文件引用)并由操作系统控制。它通常不是用户更改的设置,因为保持大量文件句柄无限期地打开操作系统资源。

This question falls into the If you have to ask, you're probably doing something wrong category. ;-)

这个问题属于如果你不得不问,你可能做错了什么类别。 ;-)

Your best bet here is to open the file, read it and then close it. Then reopen the file when you need to write out the changes. You may need to use a locking mechanism as well if you are worried about concurrent edits.

这里最好的选择是打开文件,阅读然后关闭它。然后在需要写出更改时重新打开文件。如果您担心并发编辑,则可能还需要使用锁定机制。

If you don't want to change too much logic it may help to open+read+close each file as you put it int he tree and then reopen (for write) the one(s) that are currently in the user's active view, closing them as the user navigates away.

如果你不想改变太多逻辑,那么当你把它放在树中然后重新打开(写入)当前在用户活动视图中的文件时,打开+读取+关闭每个文件可能会有所帮助,在用户导航时关闭它们。

#4


Windows deals with several kinds of handles, e.g. executive handles (files, threads), GDI handles (fonts, brushes, device contexts), user handles (windows, menus, most native controls, images). For most of these handles, there's a per-process and an overall system limit which has nothing to do with the amount of RAM available in your system. E.g. due to historical reasons, there's a limit of 10000 user handles per process and a limit of 32000 user handles per desktop session. See http://msdn.microsoft.com/en-us/library/ms810501.aspx for an in-depth explanation of handles.

Windows处理几种句柄,例如执行句柄(文件,线程),GDI句柄(字体,画笔,设备上下文),用户句柄(窗口,菜单,大多数本机控件,图像)。对于大多数这些句柄,存在每个进程和整个系统限制,这与系统中可用的RAM量无关。例如。由于历史原因,每个进程限制为10000个用户句柄,每个桌面会话限制为32000个用户句柄。有关句柄的深入说明,请参见http://msdn.microsoft.com/en-us/library/ms810501.aspx。

So first you need to make sure that you are not leaking any handles, e.g. using Sleak. Then you need to be aware that SWT uses at least one user handle for each widget (yes even for plain Composite objects). If you have a big application with lots of widgets, you'll hit the limit of 10000 user objects. I wrote a short blog entry about what we did to work around this limit in our product: http://www.subshell.com/en/subshell/blog/investigating-user-handles-with-the-swt-detective100.html. I also hacked the SWT Spy into a tool which allows me to investigate the widget tree of our application, to find places to reduce the widget count. The download link for this tool is in the blog entry.

所以首先你需要确保你没有泄漏任何手柄,例如使用Sleak。然后你需要知道SWT为每个小部件至少使用一个用户句柄(即使对于普通的Composite对象也是如此)。如果你有一个包含大量小部件的大应用程序,你将达到10000个用户对象的限制。我写了一篇简短的博客文章,介绍我们在产品中解决此限制的方法:http://www.subshel​​l.com/en/subshel​​l/blog/investigating-user-handles-with-the-swt-detective100.html 。我还将SWT Spy破解成了一个工具,它允许我调查应用程序的小部件树,找到减少小部件数量的地方。此工具的下载链接位于博客条目中。

#1


a) Try Sleak. It can find GDI-leaks in your SWT-application

a)尝试Sleak。它可以在您的SWT应用程序中找到GDI泄漏

b) You can try to change the maximum GDI handles or User object in the registry. See here and here more information.

b)您可以尝试更改注册表中的最大GDI句柄或User对象。在这里和这里了解更多信息。

You also might want to try to create a vitual tree so that only tree nodes that are shown are created.

您还可能希望尝试创建一个虚拟树,以便只创建显示的树节点。

#2


I cannot answer specifically your question, but it seems to me you are running into the maximum limit of open files a process can have at any time (judging from the "handles" term, which often refers to open files, much like file descriptors in Unix). It would be a matter of operating-system-level user permissions/capabilities then. The allowed number of open files has nothing to do with memory size.

我无法专门回答你的问题,但在我看来,你正在遇到进程可以随时拥有的打开文件的最大限制(从“句柄”术语来判断,这通常指的是打开文件,就像文件描述符一样) Unix的)。这将是操作系统级用户权限/功能的问题。允许的打开文件数与内存大小无关。

#3


Handles refers to file handles (open file references) and is controlled by the operating system. It's not typically a user changed setting because keeping lots of file handles open indefinitely hogs OS resources.

句柄指文件句柄(打开文件引用)并由操作系统控制。它通常不是用户更改的设置,因为保持大量文件句柄无限期地打开操作系统资源。

This question falls into the If you have to ask, you're probably doing something wrong category. ;-)

这个问题属于如果你不得不问,你可能做错了什么类别。 ;-)

Your best bet here is to open the file, read it and then close it. Then reopen the file when you need to write out the changes. You may need to use a locking mechanism as well if you are worried about concurrent edits.

这里最好的选择是打开文件,阅读然后关闭它。然后在需要写出更改时重新打开文件。如果您担心并发编辑,则可能还需要使用锁定机制。

If you don't want to change too much logic it may help to open+read+close each file as you put it int he tree and then reopen (for write) the one(s) that are currently in the user's active view, closing them as the user navigates away.

如果你不想改变太多逻辑,那么当你把它放在树中然后重新打开(写入)当前在用户活动视图中的文件时,打开+读取+关闭每个文件可能会有所帮助,在用户导航时关闭它们。

#4


Windows deals with several kinds of handles, e.g. executive handles (files, threads), GDI handles (fonts, brushes, device contexts), user handles (windows, menus, most native controls, images). For most of these handles, there's a per-process and an overall system limit which has nothing to do with the amount of RAM available in your system. E.g. due to historical reasons, there's a limit of 10000 user handles per process and a limit of 32000 user handles per desktop session. See http://msdn.microsoft.com/en-us/library/ms810501.aspx for an in-depth explanation of handles.

Windows处理几种句柄,例如执行句柄(文件,线程),GDI句柄(字体,画笔,设备上下文),用户句柄(窗口,菜单,大多数本机控件,图像)。对于大多数这些句柄,存在每个进程和整个系统限制,这与系统中可用的RAM量无关。例如。由于历史原因,每个进程限制为10000个用户句柄,每个桌面会话限制为32000个用户句柄。有关句柄的深入说明,请参见http://msdn.microsoft.com/en-us/library/ms810501.aspx。

So first you need to make sure that you are not leaking any handles, e.g. using Sleak. Then you need to be aware that SWT uses at least one user handle for each widget (yes even for plain Composite objects). If you have a big application with lots of widgets, you'll hit the limit of 10000 user objects. I wrote a short blog entry about what we did to work around this limit in our product: http://www.subshell.com/en/subshell/blog/investigating-user-handles-with-the-swt-detective100.html. I also hacked the SWT Spy into a tool which allows me to investigate the widget tree of our application, to find places to reduce the widget count. The download link for this tool is in the blog entry.

所以首先你需要确保你没有泄漏任何手柄,例如使用Sleak。然后你需要知道SWT为每个小部件至少使用一个用户句柄(即使对于普通的Composite对象也是如此)。如果你有一个包含大量小部件的大应用程序,你将达到10000个用户对象的限制。我写了一篇简短的博客文章,介绍我们在产品中解决此限制的方法:http://www.subshel​​l.com/en/subshel​​l/blog/investigating-user-handles-with-the-swt-detective100.html 。我还将SWT Spy破解成了一个工具,它允许我调查应用程序的小部件树,找到减少小部件数量的地方。此工具的下载链接位于博客条目中。