簡體   English   中英

JVM 如何管理 memory 的方法?

[英]How JVM manages memory for methods?

例如,我們有一個MyClass實例,它包含 1 個方法。 此方法應保存在 memory 中。 當這個MyClass實例被 GC'ed 時,對這個方法的引用是否也被刪除了? 我想弄清楚天氣通過依賴注入做所有事情(因此創建每個類的新實例)需要更少的 memory 和更高效或更簡單的Helper類以及一堆 static 方法仍然很好。

The instance methods of an object are stored in its class object (only one copy should exist), they are not "copied" with each new instance, instead, under the hood each instance holds a reference to the method implementation residing in the class object . 實例是垃圾收集而不是 class 數據。 class 數據存儲在永久空間或元空間中,具體取決於 java 版本。 垃圾收集器專門在創建實例的堆上工作,而不是在 permgen 或元空間上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM