Yes! Do not afraid to call GC.Collect() anymore

you can see a bunch of post writing that Garbage Collector on .net framework is smart enough so you should not handle it your self

the fact is, the correct statement should be

if you know the right time to call GC.Collect(), please call it
~me 😛

i realize it when developing for wp7, limited memory makes you watch the memory usage
on desktop, when memory full, it can use hard disk but on phone memory usage more than certain threshold, bam ! your apps killed
therefore having your apps small footprint memory is good, either on phone, desktop, so yes if you know the right time to call GC.Collect(), call it!

but what actually the danger stuff that people talking about?

Weak Reference
http://msdn.microsoft.com/en-us/library/system.weakreference.aspx

Telling garbage collector on what variables having weak reference is the hard part, it’s so unmanaged…
~me 😛

When you tell a variable is a weak reference, your variable can gone collected by garbage collector on unknown time
that’s the real danger!

but do not avoid it! it’s dangerous indeed, it just sometimes you must do it.

Advertisements