Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Avoid memory leak in silverlight application
6 replies. Latest Post by silverstarter on November 2, 2009.
(0)
Upendran
Member
0 points
4 Posts
09-24-2009 10:55 AM |
Hi
How to avoid the memory leak in silverlight application?
How to clear the object?
Can anybody provide sample code for avoiding the memory leak in silverlight 2.0
Thanks and regards,
Upendran P.V
Sergey.L...
Contributor
7256 points
1,354 Posts
09-24-2009 11:09 AM |
Hi,
You can use Garbage Collector for clean memory.
mchlsync
Star
14606 points
2,730 Posts
09-24-2009 11:14 AM |
Hello,
Actually, this is very big topic and you will need to conside a lot of things. .NET GC did very good job for cleaning up the object but of course, you have to be very careful when you are writing the code. The most of memory leak issues in WPF or Silverlight are becase of subscribing event handlers carelessly .
here is a nice discussion about this question in Stackoverflow. http://stackoverflow.com/questions/794466/how-to-avoid-memory-leaks
Hope you will get some idea from this link.
09-24-2009 11:20 AM |
Sergey.Lutay:You can use Garbage Collector for clean memory.
IMO, developers should not use GC.Collect without knowing the details of GC because GC is not going to collect as long as your object has some references. Instead, it will just upgrade the generation (e.g. gen0 to gen1). You may interest to read this discussioon <link>
I never recommend any developer to use GC.Collect even we found some code as below in System.Web.ISAPIRuntime :)
public void DoGCCollect(){ for (int i = 10; i > 0; i--) { GC.Collect(); }}
09-24-2009 11:21 AM |
Thank u for ur reply.
I had the used methods like GC.Collect() and GC.SupressFinalize(). But it's not working.
Can u provide a sample code for clearing the object of particular User Control.
Upendran P.V.
09-24-2009 11:35 AM |
Please read our answers first. Thanks.
Upendran:Can u provide a sample code for clearing the object of particular User Control.
1. What did you write in User Control?
2. How did you check whether those objects are already clear or not? Are you using any profiling tool?
silverst...
216 points
146 Posts
11-02-2009 10:39 AM |
hmm.. ok dont use gc.collect()
but what can i do if the used memory (on hdd) runs into 4+ GB ?
i am removing each existing eventhandler in that program in a foreach loop with -=
and then call children.clear()
when i am rebuilding the UI (quite a lot functions, something around 500-1500 including eventhandler and no i cant do it another way ;) )
is there any way to check if theres something missing?
on the testsystem the C: hdd is almost full and if that prog is tested it runs into a proxy error cause the hdd is overused
if i try it on local system the (local) hdd-memory usage goes up do ish 5GB then it seems to find an end (not growing ahead)
besides that increddible memory usage the program works realy nice!
could any one help me ?
greetings
Silverstarter