Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualGnomeTank

Posted 13 December 2012 - 12:19 PM

They aren't "pointers" in C#, they are references. This sounds like a non-important distinction, but it is important because C# has actual pointers as well.

.NET does not use reference counting, it uses a generational garbage collector where objects are moved along the generations as they are no longer rooted to another non-collected object. You'll hear the terms "anchored" or "rooted" a lot when dealing with this kind of GC. You'll also hear terms like "gen1 object" or "gen2 object", and this just has to do with where in the GC process the object is. Note that this is all true for the reference implementation of the .NET framework. It's quite possible that projects like Mono have their own implementation, though I am almost positive that Mono uses a very similar generational GC.

That said, your understanding of what's going on from a high level is correct. When you put a reference to your object in to that list, the list now holds it's "root" (or one of them anyway, you may have references in other places). The fact that the variable the reference was assigned to is local means nothing. That local variable will fall out of scope, but the reference it was attached to will not be swept by the GC because you have it anchored in that list.

#1GnomeTank

Posted 13 December 2012 - 12:18 PM

They aren't "pointers" in C#, they are references. This sounds like a non-important distinction, but it is important because C# has actual pointers as well.

C# does not use reference counting, it uses a generational garbage collector where objects are moved along the generations as they are no longer rooted to another non-collected object. You'll hear the terms "anchored" or "rooted" a lot when dealing with this kind of GC. You'll also hear terms like "gen1 object" or "gen2 object", and this just has to do with where in the GC process the object is. Note that this is all true for the reference implementation of the .NET framework. It's quite possible that projects like Mono have their own implementation, though I am almost positive that Mono uses a very similar generational GC.

That said, your understanding of what's going on from a high level is correct. When you put a reference to your object in to that list, the list now holds it's "root" (or one of them anyway, you may have references in other places). The fact that the variable the reference was assigned to is local means nothing. That local variable will fall out of scope, but the reference it was attached to will not be swept by the GC because you have it anchored in that list.

PARTNERS