简体   繁体   中英

A sample test java code which can demonstrate memory fragmentation in heap

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM