1

I am new to Eclipse RAP and have no experience with SWT or Eclipse RCP. But I understand that the developer is responsible to dispose SWT widgets because they have native peers which would block resources of the operating system.

But what about "dispose" in a RAP application? It is the browser's problem to manage operating system resources (a file dialog, maybe). So "dispose" seems unnecessary for an application that is purely RAP, correct?

Now, if I wanted to have single-sourcing with SWT and RWT, i.e. the same source code runs as a standalone RCP application and as a RAP web application. What would be a best practice regarding "dispose"? How should it be triggered? What needs to be disposed?

StaticNoiseLog
  • 1,370
  • 17
  • 27
  • I found a "Getting Started with RAP and Single Sourcing" guide. It covers the question in chapter 9 "SWT Resources". The guide is free, but registration is required: http://eclipsesource.com/en/about/contact-us/single-sourcing-guide-pdf-download/ Bottom line: Use the *Registry classes that JFace already provides. Instead of managing the resources yourself you let the registry do the work. Neither the instantiation nor the recycling of resources needs to be done manually. The big advantage is that this approach can be used in RCP and RAP so there is no need to have a different implementations. – StaticNoiseLog Aug 03 '15 at 16:11

2 Answers2

2

There is no difference between SWT and SWT/RAP when it comes to disposing of widgets.

While SWT widgets hold native OS/window system resources while not disposed, RAP widgets hold browser resources i.e. DOM nodes as long as they live. Dispose of widgets when they are no longer needed and create widgets lazily if possible.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
1

As to what needs to be disposed - anything with a dispose method! That is anything derived from Widget or Resource.

Disposing of objects derived from Widget (controls, composites, ...) is generally handled automatically when a Shell is closed.

Disposing of objects derived from Resource (things like Color, GC, Font,...) must be done by your code. You should dispose of these as soon as they are no longer needed. Failing to dispose of these objects is a common fault.

greg-449
  • 109,219
  • 232
  • 102
  • 145