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?

2
  • 1
    JVM create objects for its internal process also so you cant predict the actual no. of objects created by JVM. Commented Sep 30, 2014 at 7:36
  • i think question is answered here: [stackoverflow.com/questions/220133/java-instantiation] Commented Sep 30, 2014 at 7:54

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.