I have a question about the storage of the classes, I had created a question talking about the storage, they had answered me that ALL the classes are stored ( ClaseC a = new ClaseC()
).
So, each time you would use it, you would new Random()
be storing another class, how could you create a class like " Random()
"?
Although I understand, the problem you say is that while you instantiate more classes, you will be occupying more RAM memory with your program. If you are interested in an instance, it has two storage places (both in ram):
The heap stores the instances of your classes themselves. That is, when you make a
new ClaseA
, all you are doing is creating the instance on the heap. Now if you do youClaseA a = new ClaseA();
are creating a variable on the STACK (called: a) that has a reference to the instance, which is stored on the HEAP.I leave you an image where you can see, perhaps, more clearly what I try to explain to you:
I hope I have understood your question correctly.
In addition to what the colleague @MatiEzelQ tells you, the instances have a life cycle and this has to do with garbage collection .
There are currently two "types" of instance slots:
For each type of space there are various containers.
Young generation / New generation
This space contains 3 containers:
Old generation/Old generation
If when the collector goes through Survivor 1 it still finds that the objects there are still unreferenced, they become part of the old generation.
This build contains 2 containers: