0

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?

SamDJava
  • 267
  • 3
  • 13
  • 1
    JVM create objects for its internal process also so you cant predict the actual no. of objects created by JVM. – Mohit Sep 30 '14 at 07:36
  • i think question is answered here: [http://stackoverflow.com/questions/220133/java-instantiation] – Imran Sep 30 '14 at 07:54

1 Answers1

1

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

Community
  • 1
  • 1
Aditya K
  • 487
  • 3
  • 11