Reputation: 267
I am trying to understand the memory management scheme for JVM
Consider two classes A, B
Class A {
public A() {
//Do Something
}
}
Class B() extends A{
public B(){
super();
// DO something again
}
}
From main B b = new B();
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?
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?
Upvotes: 0
Views: 450
Reputation: 487
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.
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
Upvotes: 1