none
the problem of silverlight memory usage.

    General discussion

  •  I found the memory usage of my silverlight application increase forever.

    I do some test for this issue.

    create a childwindow item which class named "ChildWindow1", and  put a button in mainpage, in the button click event:

            private void button_Click(object sender, RoutedEventArgs e)
            {
                ChildWindow1 cw = new ChildWindow1();
                cw.Show();
            }

    run the app and check the browse's process memory in task manager, when click the button and close the showing childwindow, repeat this operation, you will see memory usage is increasing.

    In my "real" lob application, open a childwindow will increase 4~6MB of memory usage each time.

    Thursday, June 10, 2010 1:31 AM

All replies

  • 1. how about using the same instance of your child window to be shown, instead of creating a new instance everytime ? 2. You'll probably experience a garbage recollect later on in the lifetime of your app, so eventually you'll get your memory back. if you don't, then you've found a real problem !
    Thursday, June 10, 2010 3:10 AM
  • can you share the screen short

    Thursday, June 10, 2010 3:28 AM
  • We would expect the memory to increase. Garbage collection doesn't happen immediately. The question is whether, over time, it ever releases the memory. In my test with a similar scenario, it eventually does release the memory.

    You can use WinDbg to see if there truly is an issue. I talk about it in this video:

    http://csharperimage.jeremylikness.com/2010/01/introduction-to-debugging-silverlight.html

    Basically, you can find out quickly if there are still references to the object. If there are, that is the source of your memory leak. If there aren't, then eventually they will be cleaned up via garbage collection.

    Thursday, June 10, 2010 6:50 AM
  • As others have noted, Silverlight will grab memory until it sees a need to trigger the garbage collection. Still, there is the possibility of memory leaks (there is even a known issue with data templates, see http://betaforums.silverlight.net/forums/p/171739/387224.aspx).

    If you want to be sure, you could use GC.GetTotalMemory and a timer to periodically display the allocated memory. A "Collect" button calling the following code will enforce a garbage collection:

    GC.Collect()
    GC.WaitForPendingFinalizers();
    GC.Collect()

    You may still see the memory demand rising, as caches may be filled up during running the application. But you should also see a notable drop of the value from GC.GetTotalMemory.

    Thursday, July 22, 2010 3:02 AM