http://cnn237111.blog.51cto.com/2359144/1343004 GC. How collect affects garbage collection
is mainly
//GC.Collect();//GC. WaitForPendingFinalizers ();
http://q.cnblogs.com/q/35019/C# does null value for an object free memory?
Not necessarily, this involves GC garbage collection mechanism, the specific recycling is by. NET runtime, but only if the object is no longer performing any references, it will be released, that is, your a=null;
When the object must no longer be useful, the GC can reclaim the object, and the criterion for judging whether an object is no longer useful is that there is no variable pointing to it . When a variable is set to NULL.
Person p1=new person ("AA");//Create a person object in memory
person P2 = p1;//points P2 to the object that the P1 points to! This moment P1 pointed at Aa,p2 and P1 found Lilei
p1=null;//P1 no longer points to AA. AA cannot be recycled, so P2 is still pointing at it .
p2= New Person ("Gaga");//aa can be recycled because there is no variable pointing at it.
When no variable points to AA, it is no longer able to follow any of the variables to point P3 to Lilei.
When an object is discarded by the last variable that points to it (=null or variable out of scope), it is impossible to have any more variables pointing at it, it is like a kite that has broken the line, and can no longer fly back, so it will be recycled. A GC can be used when an object cannot be found.
The GC class provides methods for controlling and monitoring the GC, such as Gc.collect (), which forces the GC to start immediately, but generally does not intervene in the GC manually. For no special reason, don't call Gc.collect () and let. NET decide when to reclaim memory.
About garbage collection in C #