- Where Developers Learn, Share, & Build Careers
I'm new to C # and thinking that list1 is actually removed from memory after list1 = null;
from the list & lt; String & gt; List1 = New list & lt; String & gt; () {"Carrot", "fox", "explorer"}; & Lt; String & gt; List2 = New list & lt; String & gt; (); List2.Add (List1 [0]); List2.Add (List1 [1]); List2.Add (List1 [2]); List 1 = null; This code is for documentation only, in my real case the list item 1 is really big, and I need to remove it from memory, and only with list 2, this original The fraction of list 1 is. .
I accept the list 1 [0] and the list 2 [0] is referring to the same object in memory until I update 2 [0] with the new value. .. Is it true?
There are many questions I have to try to answer them differently:
-
Did the list 1 be removed from memory when the reference to list 1 is set to empty?
No, the collection has been removed from the list when the garbage collector is cleaning the heap for the next time. When this cleaning will be up to the garbage collector.
-
Listing the same items in List1 and List2?
Yes, they are. In conclusion, it means that you do not have to deal with memory management by this garbage collector and the garbage collector is smart enough to understand that When to collect orphan objects So do not try to do better than GC. In almost every case, it is getting worse.
Comments
Post a Comment