views:

416

answers:

3

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.

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!

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

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.

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.

A: 

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.

Paggas
+1  A: 

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.

Chris Nava
+2  A: 

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

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

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

Kire Haglin
+1 for sleak reference - it's a very handy tool
Jared