views:

225

answers:

1

I wrote a very simple newbie app with a 6-sided polyhedron (a "box") which rotates 180 degrees when I click a button. and then rotates back again on the next click. Every rotation grabs another 90MB and it doesn't let go until I close the app. The box is defined in the XAML. The Storyboard, DoubleAnimation and PropertyPath, etc, are all created ONCE, in the constructor. The button code looks like this:

    private void button_Storyboard1_Click(object sender, RoutedEventArgs e)
    {
        GC.Collect();

        if (_bFront)
        {
            _myDoubleAnimation.From = 0;
            _myDoubleAnimation.To = 180;
            _bFront = false;
        }
        else
        {
            _myDoubleAnimation.From = 180;
            _myDoubleAnimation.To = 0;
            _bFront = true;
        }
        _myDoubleAnimation.Duration = _Duration;
        Storyboard.SetTargetName(_myDoubleAnimation, "rotate_me");
        Storyboard.SetTargetProperty(_myDoubleAnimation, _PropP);
        _sb.Children.Add(_myDoubleAnimation);
        _sb.Begin(this.viewport3D1);
    }

After a few rotations I'm out of memory! What's going on?

Thanks in advance!!

+1  A: 

Could be totally wrong here, but aren't you adding _myDoubleAnimation to _sb.Children on each click, instead of just updating it?

cwap
I thought about that last night and tried doing_sb.Children.Clear(); before the Add() with no effect. I don't see a method called 'update' - what do you mean? (pardon me, I'm a wpf newbie)The gfx card is an ATi Radeon X300 which says it supports DirectX 9.0
ah-HAA! But you were right anyway! When I moved the Add to the C'Tor (so I only add it once) changes to the Animation (To... and From...) are still recognized, but no more memory leaks!Thank you!!! I still don't understand why _sb.Children.Clear() didn't help.
Nop, sounds weird :) I'd expect _sb.Children.Clear() to fix the leak as well :)
cwap