Hosting processing.org sketches in other applications, e.g. Eclipse RCP.
in
Integration and Hardware
•
2 years ago
I am hosting processing.org sketches (or rather, Java Applets that extend PApplet) within a larger application. In this case it is an Eclipse RCP application, but the principles would be the same in most application frameworks.
I have an Eclipse RCP view which hosts a processing PApplet via an Albireo SwingControl wrapper (a glorified version of the SWT_AWT bridge).
When my view is opened, I create a new PApplet, add it to the Albireo SwingControl frame, and call init() followed by start() on the Applet.
When my view is closed, I need to clean up all the resources I have allocated. In this case, since our application runs for a long period of time and can consume a lot of resources, I want to shut down Processing and aid the garbage collector in cleaning up as much as possible.
To do this, I call stop() followed by destroy(). Since I am the Applet host, and destroy() is the complement of init(), I believe this is the correct thing to do.
Inside PApplet, stop() simply pauses the animation thread. There is a comment saying that the code has moved to dispose(), but the documentation for dispose() states users must not call this. destroy() ultimately calls System.exit() which terminates everything in the running JVM. To me this is a very antisocial behaviour, given it is the complement of init(), but I accept I am very likely missing something here.
The ticket for destroy() calling System.exit() has just been marked as invalid, stating that only browsers should call destroy().
What am I doing wrong here? How should I be cleaning up processing.org sketches hosted in this way?
Many thanks!
1