Garbage Collection in .Net implementaion, objects

2019-08-29 08:30发布

I am doing some Research work on .Net libraries and conufsed about the behavior as i try to coded the objects in c# and checked them. I just want to know, that the objects are eligible for garbage collection, when any code is unable to access them? and before running GC function, can our objects referenced to some other memory, means can we move them in memory? And forexample if we implement finalizers for them, will it be must that its finalizers will be called at some point during process? I want to clear my concepts, i tried to use some c# code to do it, but i am not clear.

1条回答
看我几分像从前
2楼-- · 2019-08-29 09:25

The runtime maintains a graph of reachable objects. When GC runs and has determined that an object is a garbage then it would see that object has a Finalize method and will call the method, reclamining memory. All the objects which have Finalize method are removed from finalization queue and put into F-Reachable queue. A special runtime thread is dedicated to process this queue and call finalize method of each object.

I suggest you read following article by Jeffery Richter at MSDN. It's a 3 part article and would clear all your doubts.

http://msdn.microsoft.com/en-us/magazine/bb985010.aspx

查看更多
登录 后发表回答