使用jackson ObjectMapper时保留的堆大小更多

 钟爱胖胖 发布于 2022-12-04 15:06

我使用Jackson映射器将我的java对象转换为String,但这些对象不会被堆中的GC删除.

我的代码

List reportList; // This contains my objects

ObjectMapper map = new ObjectMapper(); // org.codehaus.jackson.map.ObjectMapper

return map.writeValueAsString(reportList);

这会将String返回到我的视图层,但是通过保留在堆中的对象映射器解析对象.我已经采取了堆转储.

Class Name              |  Objects | Shallow Heap | Retained Heap
------------------------------------------------------------------
char[]                  | 5,03,267 |  5,48,74,336 | >= 54,874,336
byte[]                  |   18,067 |  3,09,01,016 | >= 30,901,016
java.lang.reflect.Method| 2,60,262 |  2,08,20,960 | >= 32,789,040
java.util.HashMap$Entry | 4,31,423 |  1,38,05,536 | >= 92,963,752
java.lang.String        | 4,97,172 |  1,19,32,128 | >= 60,889,416
------------------------------------------------------------------

看到char

Class Name                                                            | Shallow Heap | Retained Heap
-----------------------------------------------------------------------------------------------------
[2] char[4][] @ 0x72119e690                                           |           32 |      5,28,352
'- _charBuffers org.codehaus.jackson.util.BufferRecycler @ 0x72119e658|           24 |      5,28,408
-----------------------------------------------------------------------------------------------------
Class Name                                                            | Shallow Heap | Retained Heap
-----------------------------------------------------------------------------------------------------
[2] char[4][] @ 0x721158a78                                           |           32 |      5,28,352
'- _charBuffers org.codehaus.jackson.util.BufferRecycler @ 0x721158a40|           24 |      5,28,408
-----------------------------------------------------------------------------------------------------
Class Name                                                            | Shallow Heap | Retained Heap
-----------------------------------------------------------------------------------------------------
[2] char[4][] @ 0x7210bc5e0                                           |           32 |      5,28,352
'- _charBuffers org.codehaus.jackson.util.BufferRecycler @ 0x7210bc5a8|           24 |      5,28,408
-----------------------------------------------------------------------------------------------------

如何从堆中清除这些对象,是否存在任何清理方法.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有