c# - Why is object still alive? -


Just doing some exercises and breakbacking was done through this example. I found that the references made to the first list of members were still alive, why?

The values ​​of another show and newShoe were assigned to their reference members, but as you can see, by cleaning the actual objects was given. I know that I can provide them zero values, but when they return their reference items list

  list & Lt; Shoe & gt; ShoeCloset = new list & lt; Shoe & gt; (); ShoeCloset.Add (new shoe () {styles = Styles.Sneakers, color = "Red"}); ShoeCloset.Add (new shoe) (styles = styles. Sandals, colors = "green"}); ShoeCloset.Add (new shoe () {styles = Styles flipflops, color = "yellow"}); ShoeCloset.Add (new shoe () {styles = Styles. Loophers, Color = "Brown"}); ShoeCloset.Add (new shoe () {styles = Styles.Wingtips, color = "Blue"}); // int numberoffsops = shu classcity.quarter; // foreach (shoe shoe in shoe cloacet) // {// shoe.styles = style Sneakers; // shu Clo = "white"; //} shoecloset.RemoveAt (3); Shu Neusho = Shuklosset [2]; Shu Endosho = Shoe Classet [1]; One more mourning = "gray"; Second noise. Clolo = "Green"; If (Shuclosett Cantt. (Second show)) {Console.WriteLine ("One more shoe is included"); } ShoeCloset.Clear (); anotherShoe.ToString (); // & lt; --- It is still included after the shoeCloset has been cleaned. newShoe.ToString (); // & lt; --- It is still included after the shoeCloset has been cleaned.    

Object example garbage is collected when there is no possible way for any execution code Do not reach them again because in the context of these two items you are holding through two local variables, which are still in the area, those objects are accessible, and thus are not eligible for garbage collection.

The entire point of the garbage collection is for you, no need to worry about it, you can leave it at any time (sometimes leaving some edged cases except for unsafe code and weak contexts ), Try reaching an object and find out that the object you are trying to access has accumulated garbage.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -