[Logo]
Forums Register Login
How to pool memory in Java
So - somewhat related question. Is there any way to "pool" memory in Java?
Don't know; haven't heard of it.
Please explain more, but it sounds at first hearing like something not consistent with the notion of an automatic heap.
 

Campbell Ritchie wrote:Don't know; haven't heard of it.
Please explain more, but it sounds at first hearing like something not consistent with the notion of an automatic heap.


Could be Ted, you are referring to a thread pool or the concept of concurrency?
Or do you mean how to optimize memory in Java? Is a concept that you are taking from another language you are familiar?
 

Ted Gress wrote:So - somewhat related question. Is there any way to "pool" memory in Java?



In Java, memory is always created by the VM and destroyed by the garbage collector in increments of the amount required to hold the state of some specific object(s). To get memory, you create an object (r-value) and to release memory, you let all the l-values pointing to it go out of scope or set them to null. When there are zero l-values pointing to an r-value, that r-value is eligible for garbage collection, meaning that the memory dedicated to holding its state will be marked as unallocated memory, available to hold some other object's state.

The garbage collector affectionally known as GC will get around to marking it thus as it sees fit and on its own schedule.

You cannot directly access "memory" to "pool" it  as such (except see below).

The closest things Java has to this are

1) pre-creating objects of some type before you actually need them and maintaining active references to those objects. (active l-values referencing r-values).
2) defining an Collection or array to hold a certain number of objects of some type. The VM will allocate enough memory for that many objects beofre those Collection items or array cells are ever assigned any r-values.


Exception, sort of. You can command the VM to start with a certain minimal amount of memory dedicated to it and you can also tell it to use some up to maximal amount. These are he VM arguments   -Xms and  -Xmx respectively.
I may have provided an answer to this question in your other very similar thread: https://coderanch.com/t/688127/java/Freelists
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss


This thread has been viewed 162 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 19, 2018 20:47:35.