How to memory profile in Java?

前端 未结 6 2058
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 03:38

I\'m still learning the ropes of Java so sorry if there\'s a obvious answer to this. I have a program that is taking a ton of memory and I want to figure a way to reduce its

6条回答
  •  暖寄归人
    2020-12-01 04:08

    If you use visualVM to check your memory usage, it focuses on the data, not the methods. Maybe your big char[] data is caused by many String values? Unless you are using recursion, the data will not be from local variables. So you can focus on the methods that insert elements into large data structures. To find out what precise statements cause your "memory leakage", I suggest you additionally

    • read Josh Bloch's Effective Java Item 6: (Eliminate obsolete object references)
    • use a logging framework an log instance creations on the highest verbosity level.

提交回复
热议问题