JDK-8113904 : Need Toolkit shutdown hook to clean up resources, etc.
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: fx2.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2011-08-03
  • Updated: 2022-07-21
  • Resolved: 2011-08-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
fx2.0Fixed
Related Reports
Blocks :  
Relates :  
Description
We need a Toolkit shutdown hook that can be used by other parts of the system (e.g., media) to clean up resources, etc. Something like:

public void Toolkit.addShutdownHook(TKShutdownHook hook);
public void Toolkit.removeShutdownHook(TKShutdownHook hook);

These shutdown hooks would be called by Toolkit.exit() on the JavaFX application thread and could be used to dispose of resources.
Comments
Verified both by code inspection and by observed behavior (audio shutdown is working).
07-09-2011

Kevin, could you please verify this issue or provide steps to reproduce it?
07-09-2011

Even better, we could use the same object as the stage pulse listener and only register a single shutdown hook to clean up graphics resources.
10-08-2011

Yes we should be able to do that.
10-08-2011

The latter would be fine as long as you don't register a shutdown hook for each MediaView. Since the MediaPlayer would have a list of MediaViews using it, you should be able to cleanup in the MediaPlayer shutdown hook, right?
10-08-2011

Should also dispose of graphics resources allocated by MediaViews (and their peers), but that would be a good start.
10-08-2011

Looks good. So for example javafx.scene.media.MediaPlayer would implement TKShutdownHook and register itself with Toolkit.getToolkit().addShutdownHook()? The implementation of TKShutdownHook in MediaPlayer would at least be: public void run() { jfxPlayer.dispose(); } Possibly some other minor cleanup might be needed but this is TBD.
10-08-2011

Fixing this would in effect clear up RT-13897. There is still a question however surrounding the latter with respect to hard references to MediaView held by Scene.
05-08-2011