0

I would like to understand on how a memory fragmentation can occur by writing some bad code in the java user space.

Please point out me with some ideas which can help me to understand this.

In my understanding I was thinking like, java heap fragmentation can only occur because of buggy Garbage collection, but some of my friends argued for the opposite.

I just want to understand that Java Heap fragmentation can occur by writing bad java code applications as well.

NB: I am looking for code snippets which can demonstrate this argument.


UPDATE:

Actually the jvm which we have in the embedded device is java 1.3.

Thanks,
Sen

Navaneeth Sen
  • 6,315
  • 11
  • 53
  • 82

1 Answers1

0

First of all, the garbage collector is JVM specific. I only know OpenJRE and the Sun JRE. The garbage collectors used there compact the heap during the collection, thus heap fragmentation can NOT occur due to the design of the memory management.

Other algorithms for memory management, which got used more often in the past, use a free list and did not move memory around in the heap. For such management schemes heap fragmentation can be an issue.

ruediste
  • 2,434
  • 1
  • 21
  • 30
  • It depends on what GC type is used. CMS will fragment the heap while G1 won't. G1 isn't the default in 1.8.0_05, so heap fragmentation will occur if you don't change the settings. – Thomas Jungblut Jun 20 '14 at 16:13
  • Reading http://www.oracle.com/technetwork/java/javase/tech/memorymanagement-whitepaper-1-150020.pdf, page 13, I'm not sure if the collector reverts to a compacting algorithm if space gets tight. – ruediste Jun 20 '14 at 17:39