在 Java 中是否收集了永久代空间垃圾?

2022-01-16 00:00:00 garbage-collection java

我已经读到 Perm gen(或 Permanent Generation)空间不是垃圾收集的.但是,在 CMS 集合中,我可以在 GC 日志中看到一些类正在卸载.那么 perm gen 垃圾是在完全收集还是 CMS 收集期间收集的?

I have read that Perm gen (or Permanent Generation) space is not garbage collected. However, in CMS collection I can see some classes unloading in my GC log. So is perm gen garbage collected during full collection or CMS collection?

推荐答案

PermGen 像堆的其他部分一样被垃圾收集.

The PermGen is garbage collected like the other parts of the heap.

这里要注意的是,PermGen 包含类和对象的元数据,即指向分配对象的堆的其余部分的指针.PermGen 还包含在使用结束时必须手动销毁的类加载器,否则它们会保留在内存中并保持对堆上对象的引用.Jon Masamitsu 在 Sun/Oracle 博客网站上的 "Presenting the Permanent Generation" 文章可能帮助你.

The thing to note here is that the PermGen contains meta-data of the classes and the objects i.e. pointers into the rest of the heap where the objects are allocated. The PermGen also contains Class-loaders which have to be manually destroyed at the end of their use else they stay in memory and also keep holding references to their objects on the heap. The "Presenting the Permanent Generation" article by Jon Masamitsu on the Sun / Oracle blog site might help you.

相关文章