garbage collection - C#: In what cases should you null out references? -


CLR profiler can also explain which ways you can allocate more storage than expected, and You can uncover cases where you are unknowingly referring to the waste object graph which can otherwise be recovered by GC. (A common problem is the design pattern is a software cache or lookup table that is no longer necessary or is safe to reconstruct later. This is a tragic event when the cash object keeps the graph alive before its useful life, Instead, exit the objects that you no longer need .) -

I do not think I actually never end a reference Have done me Think you do not always need to do, but I think a time also when it is important to remember to do. But, what matters is that? When should you end the references, should the reference be terminated?

To be "alive", but you do not want context to prevent garbage collection. In other words, if the object holds the reference of A object B, and you do not need B, but will survive for some other reasons. Another common example is the stable variable, which is "alive" for AppDomain.

This almost is never necessary for local variables, because GC may find the last possible point in the code where a variable will be used. However, if you use the declared variable outside of a loop during the first walk, but you know that you will not need it for its iterations, you can set the object to To help you become eligible for GC first.

In my experience, it is rare for me to find myself in this situation, for the sake of GC, I hardly cancel the set variable. Normally all member variables within the object are "useful", unless the object itself is eligible for GC. If you meet with your member variable which is not useful for the whole life of the object, then you want to see if it indicates a problem with the design.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -