Are the data of the variables or objects initialized in the constructor method stored in RAM directly?

0

That is: If I initialized an object "x" in the constructor method, will I have quick access to it when I use it somewhere in my code? Is it stored directly in RAM? Or is there a buffer between the RAM and the JAVA virtual machine? As well as a kind of Cache.

I want to know this thoroughly to determine at what point I should initialize a variable or declared object within my class. This to improve the performance of my application

    
asked by Missionary robot Robot 22.11.2018 в 01:19
source

1 answer

2

For the purposes of your application, if , when invoking the constructor, space is reserved in RAM and that instance of the object is stored there.

For your program, this object will keep occupying that memory until after leaving context and a little more time, when the garbage collector runs again, and then that memory will be released.

Now, it is likely that this instance is not really in RAM all the time. For example, that the operating system lower temporarily the page of memory where your instance of object to disk resides, if the system is limited of resources (or not, in the case of linux). This optimization is done as part of the management of virtual memory of modern operating systems and allows a machine to exceed its original memory capacity (at the cost of a large loss of performance ).

That if, at the moment that your program accesses some data contained within the object, to read it or modify it, it will be placed again in RAM so transparent a your program, because it is only in the RAM where this operation can be performed.

In fact, this is done so transparently that you can not do much to prevent this from happening, except to be using the object all the time.

What your program will experience in that case, is some delay.

Today, in many architectures, the JVM interacts in a coordinated with the base operating system so that the performance is acceptable.

    
answered by 23.11.2018 / 01:57
source