SimpleCanvasImpl not calling finalize method

I have a program that provides a Canvas to a JPanel using a subclass of SimpleCanvasImpl. When the panel is garbage collected I want the properties to be written out to file so I've written a finalize method as follows.

    protected void finalize() throws Throwable

        File propFile = new File("user.inf");
        System.out.println("Saving user properties file " + propFile.getAbsolutePath());"Saving user properties file " + propFile.getAbsolutePath());
            OutputStream os = new FileOutputStream(propFile);
            properties.storeToXML(os, "Furion user properties");
        catch (Exception e)
            System.err.println("Error saving user properties file " + e);
            logger.severe("Error saving user properties file " + e);

My problem is that the finalize method isn't being called. Is this an issue with SimpleCanvasImpl or is there a better solution that anyone can suggest.

Many thanks in advance for any help

SimpleCanvasImpl and any other jME classes have nothing to do with what methods are called on your JPanel, that's  AWT stuff. I think the method you're looking for is removeNotify:

Actually finalize comes from Object and should be called when an instance becomes ready for garbage collection. The whole point being that this is where you put your cleanup code. As SimpleCanvasImpl extends from Object I would expect it to have it's finalize method called unless something further up the chain was blocking the inheritance.

Last time I checked, there's only a small chance the finalize method will be called on an object when it's garbage collected. Therefore it's best to not use that method but rather implement your own cleanup system. Either way, SimpleCanvasImpl or any other class in jME does not implement finalize so this is an issue between you and the VM only.

Thanks for the reply. I was hoping that it would be one of those lucky classes that gets called at least most of the time. Problem I have is that I'm developing a 3D JPanel extension api of other development teams to use so I can't guarantee that they would implement any cleanup code when their application closes. Guess I'll just have to write those disclaimers into my Javadoc so at least I can point the finger of blame when they complain.  XD