• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to pool memory in Java  RSS feed

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So - somewhat related question. Is there any way to "pool" memory in Java?
 
Marshal
Posts: 56820
173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 434
7
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 22949
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may have provided an answer to this question in your other very similar thread: https://coderanch.com/t/688127/java/Freelists
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!