I'm trying to diagnose a java.lang.OutOfMemoryError: PermGen Space
error when running on Sun's Hotspot JVM, and would like to know how much PermGen space my program is using at various points. Is there a way of finding out this information programmatically?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can use something like this:
Iterator<MemoryPoolMXBean> iter = ManagementFactory.getMemoryPoolMXBeans().iterator();
while (iter.hasNext())
{
MemoryPoolMXBean item = iter.next();
String name = item.getName();
MemoryType type = item.getType();
MemoryUsage usage = item.getUsage();
MemoryUsage peak = item.getPeakUsage();
MemoryUsage collections = item.getCollectionUsage();
}
This will give you all types of memory. You are interested in "Perm Gen" type.
回答2:
Try ManagementFactory.getMemoryPoolMXBeans()
.