Java中的对象创建逻辑 [英] Object Creation Logic in Java

查看:74
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆