使用App时Java内存使用量增加,但不被使用时不会减少

我有一个使用大量内存的 java应用程序,但是当程序未被使用时,内存使用情况不会下降.

有没有办法强制Java释放这个内存?因为那时候不需要这个内存,所以我可以理解为了保留少量的内存,但是Java只是保留所有使用的内存.它还会再次重用这个内存,但是当它不需要时,必须有一种方法来强制Java释放它.

System.gc不工作.

解决方法

正如在评论中指出的那样,当垃圾收集器处理对象时,它不能确定,它会给系统留下回忆.

也许Tuning Garbage Collection Outline为您的问题提供了解决方案:

By default the JVM grows or shrinks the heap at each GC to keep the ratio of free space to live objects at each collection within a specified range.

  • -XX:MinHeapFreeRatio – when the percentage of free space in a generation falls below this value the generation will be expanded to meet this percentage. Default is 40
  • -XX:MaxHeapFreeRatio – when the percentage of free space in a generation exceeded this value the generation will shrink to meet this value. Default is 70

否则,如果您怀疑您漏掉引用,您可以确定如何监控JVisualVM(与标准SDK捆绑在一起的工具)中监控堆的泄漏情况.您可以通过此程序执行堆转储并获取对象内存消耗的直方图:

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...