Potential Out Of Memory Error during startup using Eclipse compatibility layer

aurelien.pupier's picture
aurelien.pupier
Blog Categories: 

After migrating from Eclipse 4.3 to 4.4.1, we got some Out Of Memory Errors during the startup of our Eclipse RCP application on our CI server. Here's how we spotted and solved the issue!

How to spot the memory issue

In the Heap Dump, we can see that there are a lot of elements kept in the UISynchronizer.pendingStartup list: pendingStartup70Mo UISSYnrchronizer lot of entries

Why is this happening?

There are two key reasons:

  • The UISynchronizer is waiting for the startup of the Application and the Eclipse 4 Workbench to be completed before executing Runnables. A look into the code was useful to understand this:
/**
 * Indicates that the UI is in startup mode and that no non-workbench
 * runnables should be invoked.
 */

protected boolean isStarting = true;

/**
 * List of non-workbench Runnables that need executing at some point in the future
 */

protected List pendingStartup = new ArrayList();

...
protected void asyncExec(Runnable runnable) {
...
        if (isStarting ....) {
                // don't run it now, add it to the list of deferred runnables
                pendingStartup.add(runnable);
                return;
        }
}
  • The postStartup hook in Eclipse 3.x is called before the Eclipse 4 Workbench and Application creation when using the compatibility layer: WorkbenchLifecycleWithCompatLayer

How to solve the issue

If you are using the postStartup hook in WorkbenchWindowAdvisor, be careful to not call any code with Runnable which is not WorkspaceRunnable.

The best solution, of course, is to embrace Eclipse 4 API and not use the postStartup old hook any longer! Use the Eclipse 4 LifeCycle API and listen for the UIEvents.UILifeCycle.APP_STARTUP_COMPLETE event. I recommend you follow Lars' tutorial - excellent as usual - to learn how to implement it.

Notifications