• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to pool memory in Java

 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So - somewhat related question. Is there any way to "pool" memory in Java?
 
Marshal
Posts: 80066
410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 607
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 28344
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic