日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

GC分析中提到的根对象是什么

發(fā)布時(shí)間:2024/4/17 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 GC分析中提到的根对象是什么 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一些文章在分析GC時(shí),不可逾越的說到要先從根對(duì)象掃描出不可達(dá)對(duì)象,然后標(biāo)記那些不可達(dá)對(duì)象為垃圾。那么源頭根對(duì)象是什么玩意呢?

幾分鐘后google到比較可信源是http://stackoverflow.com/questions/8458886/what-is-a-rooted-reference。其解釋具體為:

GC roots are not objects in themselves but are instead references to objects. Any object referenced by a GC root will automatically survive the next garbage collection. There are four main kinds of root in .NET:

?

1,A?local variable in a method that is currently running(GC發(fā)生時(shí),當(dāng)前正在執(zhí)行的方法中那些本地變量)?is considered to be a GC root. The objects referenced by these variables can always be accessed immediately by the method they are declared in, and so they must be kept around. The lifetime of these roots can depend on the way the program was built. In debug builds, a local variable lasts for as long as the method is on the stack. In release builds, the JIT is able to look at the program structure to work out the last point within the execution that a variable can be used by the method and will discard it when it is no longer required. This strategy isn’t always used and can be turned off, for example, by running the program in a debugger.

2,Static variables(靜態(tài)變量)?are also always considered GC roots. The objects they reference can be accessed at any time by the class that declared them (or the rest of the program if they are public), so .NET will always keep them around. Variables declared as ‘thread static’ will only last for as long as that thread is running.

3,If?a managed object is passed to an unmanaged COM+ library through interop(非托管類似COM+一樣通過interop被使用的對(duì)象, then it will also become a GC root with a reference count. This is because COM+ doesn’t do garbage collection: It uses, instead, a reference counting system; once the COM+ library finishes with the object by setting the reference count to 0 it ceases to be a GC root and can be collected again.

4,If?an object has a finalizer(實(shí)現(xiàn)了finalizer接口的對(duì)象, it is not immediately removed when the garbage collector decides it is no longer ‘live’. Instead, it becomes a special kind of root until .NET has called the finalizer method. This means that these objects usually require more than one garbage collection to be removed from memory, as they will survive the first time they are found to be unused.

推薦【譯】.Net 垃圾回收機(jī)制原理(一),其中也提到了finalizer有重活機(jī)會(huì)。

?

轉(zhuǎn)載于:https://www.cnblogs.com/wusong/p/3282283.html

總結(jié)

以上是生活随笔為你收集整理的GC分析中提到的根对象是什么的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。