| [news.eclipse.platform.swt] Re: OutOfMemoryError on event-handling thread |
|
David, Comments below. David Huebel wrote: Or, as suggested in the other post, you could allocate a bunch of storage up front as a reserve. You might even release it so that your JVM could hobble along.Ed Merks wrote: If suppose if a job is doing something and terminates that the memory that being used might well be collectible.However, I have seen my Eclipse application pop up an error dialog saying, "OutOfMemoryError: Java heap space". Surely the JVM must have allocated some heap memory to accomplish that? And I have (several times at least) seen that OOMEs thrown and handled by Jobs, after which the application continued to function normally. Yes, of course. Indeed. Though something is likely to have failed miserably and might have left things in not a great state.If it is possible to make some objects collectable without doing more heap allocation, then the JVM should continue operating normally. Yes, and you could set that aside up front. Typically you have lots of small objects and not so many really big ones.I do allocate large arrays to hold the data -- though presumably most of the allocation done by SWT/JFace on the event-handling thread to render my tables is of small objects. Who knows. An editor opening a really big file might well allocate some large arrays... That depends on how the rest of the system is handling the failure. Should an editor failing to open dispose itself and does it?Ideally, if some kind of error (such as on OOME) prevented a table from being rendered, the objects that were allocated for that purpose would remain in a collectable state. If it's important to fail more gracefully, it's best to tip the odd in your favor rather than to rely on them hopefully being that way.I.e., a Table couldn't be put in a state where it references objects that it isn't using. Much much easier said than done, of course, but odds are that at least *some* heap objects would be referenced only from the stack, meaning that by the time the OOME is caught, the garbage collector can free some objects and relieve the heap pressure. Yes, assuming that you have control of what's likely to fail. But there's always the straw that breaks the camel's back, and it could be a small straw.Plus, if I can run a handler, I can turn the most recently loaded dataset into garbage, which should free up plenty of memory. I know exceptions that percolate outside of the event loop bring up a message box and I know stack overflow exceptions suggest that the process be shutdown (which I sometimes ignore when debugging). It suppose it's also possible to detect impending heap exhaustion, so you might produce a warning up earlier or avoid taken an action likely to exhaust the heap (editing a large data set)...I'm getting the sense that the answer to my question: - David |