0

Is there a fixed amount of memory allowed for a process as a barrier. because after generating a lot of objects in the heap ~ 3*10^8 JVM consumes about 1.162.4 GB of ram and after that it gives OutOfMemoryError. why can't i generate objects till the end of the capacity of the heap? or is this related to the JVM or the operating system is doing this?

class c  {
    public static void main(String str[]){
        int a[] = new int[300000000];

        while(true){}
    }
}
Raj Kumar
  • 160
  • 2
  • 7
  • Possible duplicate of [How to deal with "java.lang.OutOfMemoryError: Java heap space" error?](https://stackoverflow.com/questions/37335/how-to-deal-with-java-lang-outofmemoryerror-java-heap-space-error) – xmojmr Sep 02 '19 at 12:13
  • no its not please don't spoil the question ... i did't got the exact answer... as i said i my system i am able to use 1.2 GB for allocation instead of 2GB as stated by https://stackoverflow.com/questions/37335/how-to-deal-with-java-lang-outofmemoryerror-java-heap-space-error – Raj Kumar Sep 02 '19 at 20:26
  • Can you check your numbers? 3*10^9 represented in 1.2GB is about 0.42 bytes per object. That seems a little low. – mevets Sep 03 '19 at 03:28
  • A bit more reasonable, 4.2 bytes per object; but given that somewhere there has to be a pointer to the object (4 bytes), and some garbage collection info, I find this still a bit too small. Where are you storing your object references? If you aren't assigning them to a list, map, ..., https://plumbr.io/outofmemoryerror/gc-overhead-limit-exceeded might be your issue. – mevets Sep 03 '19 at 12:57
  • @mevets edited again.. and data it 100% accurate .. hope this helps.. – Raj Kumar Sep 03 '19 at 13:42
  • I am over my head. I tried your program; it seem to consistently oom @ 250 000 000, which corresponds to 1G of memory just for the object. – mevets Sep 03 '19 at 14:22
  • are you able to conclude anything now ?? – Raj Kumar Sep 03 '19 at 17:48

0 Answers0