Bug: GC cant clean up JMEDesktop

Hi Folks,

i run into the Problem of an OutOfMemoryException during using GameState -switching with JMEDesktop using. I have several GameStates, all with their own JMEDesktop, but online one State is active at a given time. When i switch to a new state, the old one gets cleared. The State itself gets GCed, cuz i dont keep any reference to it, but not the JMEDesktop and my JComponents on it. So i started up my profiler and digged into the search for the damn memoryleak.

The prob is that the dispose method of JMEDesktop doesnt really clean everything and it seems without calling it nothing would ever been released. During startup it registers Actions(Triggers) on the MouseInputDevice  and they dont get unregistered and there we have the always alive reference to the JMEDesktop. The MouseInputDevice is in a static Hashmap and its listener queue still contains the old JMEDesktop Actions.

Even i removed all of my components from the JDesktopPane one is still referenced by the JMEDesktop.lastComponent field and would be released, cuz the JMEDesktop is still alive. Problem above.

As far as i see, the dispose method must be extended to unregister those ActionsListeners. I just tested clearing the reference of lastCopmponent field and my stuff gets collected then. Got to tired to test the rest yesterday night :slight_smile:

When will it be fixed? :slight_smile:



hmmm seems theres still another problem. Even when i clear the lastComponent my swing objects can still pop up again. And the JMEDesktops are all alive. At least thats what Reference Scanner is showing. A few times it showed me references to swing eventlisteners or other swing stuff. odd :? 

any clue?

With the standard heap size of max 64MB i get the OutOFMemeoryExceptions after a few Stateswitches. Using jdk 1.5_03 and updated just to 06. Same.

Not sure i f i get the time to investigate this any further. For now i increased the heap size.

Thanks for investigating this! I think I have fixed it - please double check.

I added this to the cleanup method of TestJMEDesktop:

        WeakReference ref = new WeakReference( jmeDesktop );
        jmeDesktop = null;
        desktopNode = null;
        System.out.println( ref.get() );

It prints 'null' after I added a removeAll() and detachNode() to the dispose method - so the JMEDesktop gets gc'ed. Your problem still there?

Nope, seems to work now. The OutOfMemory didnt occure again during testing. woohoo :slight_smile:

Buts funny, when i trace via WeakReference by myself its gone, if i use the tool its still there, even its using WeakReferences too.

Thanks for support.