Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# garbage collection with object references

In C#, when I have two object obj1, obj2 composed of a List<string> and I assign both of those objects to the same List<string> object.

If my reference to obj1 goes out of scope but my reference to obj2 does not, is obj1 still eligible for garbage collection, or are there some dependency issues because there is still a reference to the List<string> object?

like image 977
user623879 Avatar asked Mar 21 '26 20:03

user623879


1 Answers

obj1 should be eligible for garbage collection as long as there are no references to obj1 itself.

like image 92
Mrchief Avatar answered Mar 24 '26 08:03

Mrchief



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!