问题描述
内存溢出 OutOfMemory:heap space
排查分析
1.打印dump
jmap -dump:format=b,file=dump.hprof pid
2.用jvisualvm打开dump文件
建议使用jdk自带内存分析jvisualvm,mat和jprofiler有时打不出来溢出对象
![](https://img.haomeiwen.com/i15602316/da9edf36a25ce5da.png)
3.定位异常代码
打开类视图,可看到占用内存大的对象
![](https://img.haomeiwen.com/i15602316/5b08117cb0d73b45.png)
![](https://img.haomeiwen.com/i15602316/f46612c577f4e3be.png)
char数组溢出,创建超过数组最大大小,可将数组保存文件用more命令分析具体值,逐级分析实例引用,可发现请求后台的action,从而找到对应的源码
![](https://img.haomeiwen.com/i15602316/197f5065ad06fca0.png)
4.结论
该char数组是Hibernate PO对象,使用懒加载机制外键关联其他表,action处理请求返回前台PO对象转换的JSON串异常。
![](https://img.haomeiwen.com/i15602316/4395bb7297ba7fe5.png)
解决
1.json过滤lazy属性字段: 加注解@JSON(serialize=false)
2.转化前直接赋null,级联类型ALL和REMOVE不要这么做
3.设置JSON-LIB的setCycleDetectionStrategy属性让其自己处理循环,省事但是数据过于复杂的话会引起数据溢出或者效率低下,慎用
网友评论