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();
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.
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 !
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:
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.
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:
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.