Java中的对象创建逻辑 [英] Object Creation Logic in Java
问题描述
我试图了解JVM的内存管理方案
I am trying to understand the memory management scheme for JVM
考虑两个A,B类
Class A {
public A() {
//Do Something
}
}
Class B() extends A{
public B(){
super();
// DO something again
}
}
从主要 B b =新的B();
From main B b = new B();
据我所知,类加载器将加载A,B并分别创建2个对象.还有其他可以创建的对象吗?
As per my knowledge the Class loader will load A, B and will create 2 objects each. Is there any other object that would get created?
我的问题的第二部分是,在访问Java Visual VM时,我看到Java NIO包的对象已创建.有什么方法可以阻止JVM创建与项目无关的对象?
Also the second part of my question is that , while accessing Java Visual VM , I see objects of Java NIO package has been created. Is there any way I can prevent JVM from creating objects which are not related to my project?
推荐答案
第一个问题的答案是将只创建一个对象.基本上,对于每个新"语句,都会创建一个对象.因此,我认为您对正在创建的两个对象的评估是错误的.
The answer to your first question is that there will be only one object created. Basically, for every "new" statement, there is one object created. So I think your assessment about two objects being created is wrong.
第二,我不认为您对JVM具有关于所创建对象(与您的项目无关)的任何控制权.
Secondly, I do not think you have any control on the JVM with respect to the objects that are created (not related to your project).
Lastly, for a more detailed answer to the first part of your question you can take a look here
这篇关于Java中的对象创建逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!