how Usages of object resurrection

 

Questions


I have a problem with memory leaks in my .NET Windows service application. So I’ve started to read articles about memory management in .NET. And i have found an interesting practice in one of Jeffrey Richter articles. This practice name is “object resurrection”. It looks like situating code that initializes global or static variable to “this”:

protected override void Finalize() {
     Application.ObjHolder = this;
     GC.ReRegisterForFinalize(this);
}

I understand that this is a bad practice, however i would like to know patterns that uses this practice. If you know any, please write here.

 

 

————————————————-

Answer

Speculative: In a Pool situation, like the ConnectionPool.

You might use it to reclaim objects that were not properly disposed but to which the application code no longer holds a reference. You can’t keep them in a List in the Pool because that would block GC collection.

c#,clr,memory-management

Facebook Comments

Post a comment