Skip to main content

Animator ScreenTransition OutOfMemory

9 replies [Last post]
dpmihai
Offline
Joined: 2006-08-04

Hello.

I want to create a wizard with animation effect between screens using back and forward buttons. I started from a RichClient example SearchTransition. I have the same MoveIn Effect as in the book
After a lot of transitions (back, forward in the wizard) I get OutOfMemory.
Does anyone else got this?

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.(Unknown Source)
at java.awt.image.Raster.createPackedRaster(Unknown Source)
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
at sun.awt.Win32GraphicsConfig.createCompatibleImage(Unknown Source)
at java.awt.GraphicsConfiguration.createCompatibleImage(Unknown Source)
at org.jdesktop.animation.transitions.ComponentState.createSnapshot(ComponentState.java:66)
at org.jdesktop.animation.transitions.ComponentState.(ComponentState.java:52)
at org.jdesktop.animation.transitions.AnimationManager.setupEnd(AnimationManager.java:154)
at org.jdesktop.animation.transitions.ScreenTransition$1.begin(ScreenTransition.java:267)
at org.jdesktop.animation.timing.Animator.begin(Animator.java:743)
at org.jdesktop.animation.timing.Animator.getTimingFraction(Animator.java:871)
at org.jdesktop.animation.timing.Animator$TimerTarget.actionPerformed(Animator.java:1041)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dpmihai
Offline
Joined: 2006-08-04

This memory leak was also mine.

I added to MoveIn effect the following (for the PropertySetter)

public void cleanup(Animator animator) {
super.cleanup(animator);
animator.removeTarget(ps);
}

and called it after every animation update. So no need to modify the Animator class.

correainfo
Offline
Joined: 2007-03-19

Could I spend an example of how you solved the problem 1

dpmihai
Offline
Joined: 2006-08-04

You were right about the listener. But there is another OutOfMemory problem which occurs after some time (not as fast as the first) :

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.(DataBufferInt.java:41)
at java.awt.image.Raster.createPackedRaster(Raster.java:458)
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015)
at sun.awt.Win32GraphicsConfig.createCompatibleImage(Win32GraphicsConfig.java:131)
at java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:155)
at org.jdesktop.animation.transitions.ComponentState.createSnapshot(ComponentState.java:109)
at org.jdesktop.animation.transitions.ComponentState.(ComponentState.java:94)
at org.jdesktop.animation.transitions.AnimationManager.setupEnd(AnimationManager.java:213)
at org.jdesktop.animation.transitions.ScreenTransition$1.begin(ScreenTransition.java:356)
at org.jdesktop.animation.timing.Animator.begin(Animator.java:743)
at org.jdesktop.animation.timing.Animator.getTimingFraction(Animator.java:871)
at org.jdesktop.animation.timing.Animator$TimerTarget.actionPerformed(Animator.java:1041)
at javax.swing.Timer.fireActionPerformed(Timer.java:271)
at javax.swing.Timer$DoPostEvent.run(Timer.java:201)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

boerkel
Offline
Joined: 2003-08-10

HI!

I am also seeing an OOM. The bigger the window, the earlier. And it only happens with Windows L&F.

I have a small test program to demonstrate this.

I'll try the suggested fix.

Thomas

boerkel
Offline
Joined: 2003-08-10

HI!

OK, the suggested fix works for me.

I added an issue:
https://animatedtransitions.dev.java.net/issues/show_bug.cgi?id=4

Thomas

marcinbablok
Offline
Joined: 2009-01-06

I have found a memory leak in the code in FadeIn and FadeOut classes. They both add a PropertySetter object as a target to Animator, and that propertySetter object has referrences to some images created during transitions.

My solution was to implement a method in Animator class to remove all targets that were an instance of PropertySetter class and call it after an end to each transition end method of the main transition target in ScreenTransition class.

public void removePropertySetterTargers() {
TimingTarget target;
for ( Iterator it = targets.iterator(); it.hasNext() ; ) {
target = it.next();
if ( target instanceof PropertySetter ) {
it.remove();
}
}
}

boerkel
Offline
Joined: 2003-08-10

Hmm, shouldn't those PropertySetters be collected by the GC, when the Animator class goes out of scope?

flyaruu
Offline
Joined: 2007-05-18

Yes, there is a leak in the Transition framework, I had the same problem.
As far as I know, the only way to fix it is hack around in the sourcecode.

In the constructor of ScreenTransition, it registers a listener to the component you are doing the transition for:

containerLayer.addComponentListener(new ContainerSizeListener());

This listener is never removed, and it will prevent the garbage collection of the ScreenTransition, the Animator, and some other classes. I leaks pretty fast, so it is easy to reproduce.

To fix this, you need to assign the ContainerSizeListener to a field, and remove it after the transition has finished.

regards, Frank

Dexels

rah003
Offline
Joined: 2004-05-26

Please log the issue at https://timingframework.dev.java.net/issues
Thanks