Potential Out Of Memory Error during startup using Eclipse compatibility layer

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:
  1. /**
  2.  * Indicates that the UI is in startup mode and that no non-workbench
  3.  * runnables should be invoked.
  4.  */
  5. protected boolean isStarting = true;
  6.  
  7. /**
  8.  * List of non-workbench Runnables that need executing at some point in the future
  9.  */
  10. protected List pendingStartup = new ArrayList();
  11.  
  12. ...
  13. protected void asyncExec(Runnable runnable) {
  14. ...
  15. if (isStarting ....) {
  16. // don't run it now, add it to the list of deferred runnables
  17. pendingStartup.add(runnable);
  18. return;
  19. }
  20. }
  • 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