jueves, julio 08, 2004

Garbage Collection in the .Net Framework

Some time ago I was reading some papers about Garbage Collection, which is the process of managing the allocations and deallocations of memory in an environment. Unfortunately, that information is hard to find in the web, since only some little info or slides are avalaible (I found an interesting book at amazon about GC, but it is so expensive).

Since that, I'm trying to read that little info, and since I could access the ACM digital library, I'm going to check some related papers. However, I have the experience that this kind of papers only cover the theorical part, and thus are not enough for me (I have more than a just theorical interest on GC).

However, I found good papers in the MSDN site and currently I'm reading the GC internal. Those papers are interesant, but again, they do not cover the area I'm interesting in (of course that I'm interested in the area they cover, it is just that I need some more information).

Something very interesant is a process called Resurrection, by which a dead object (unreachable and thus marked for being deleted from the memory) can be resurrected. Imagine you have an object that has a Finalizer method (destructor syntaxis in C#) that assigns a global/static variable a pointer to your current object:

~MyClass ()
// 'this' refers to the current instance
MyNamespace.AnyClass.AnStaticObject = this;

When and object has a Finalizer (destructor in C#), is added to an internal GC data structure called F-Reachable queue, that contains pointers to object that need to be finalized before they get deleted. However, if you have something like the previous code, your object will live again, but its Finalize method won't be called when it becomes -again- unreachable.

In fact, resurrection should NEVER happen. Just for the purpose of 'security', if the object needs to be finalized, an internal boolean flag could be added, keeping the state (finalized or not) and throw an expection when a method is called (throwing an expeption from the Finalizer would only finish the method).

2 comentarios:

Roberto Iza Valdes dijo...
Este blog ha sido eliminado por un administrador de blog.
Roberto Iza dijo...
Este comentario ha sido eliminado por el autor.