【发布时间】:2018-03-11 14:38:51
【问题描述】:
我在 AIX 服务器 IBM java 中遇到了一些堆内存问题。
首先说明问题,下面是java中由C#代码调用的方法,Java代码返回数组列表。即报告对象运行方法给出了数组列表。然后 c# 代码会将数组列表写入文件。这是现有的框架。
public List runReport( Integer ifeId, List params ) throws ReferenceCoreException
{
ReportInterface report=new ReportInterface();
// sanity check
// run the report
// MED: need a way of getting this session's data source
return report.run( HibernateSession.getDataSource(), ifeObj, params);
}
catch ( Exception e )
{
throw new ReferenceCoreException( e );
}
}
每当我们进行堆转储时,它都会显示内存已被完全占用。即 Xmx 为 8 GB,堆转储也显示 7.9 GB 已满。
我的问题是:一旦返回数组列表,最好由 GC 清除它。如果不能,我可以添加 finally 块并将报告对象设置为 null,如下所示?
public List runReport( Integer ifeId, List params ) throws ReferenceCoreException
{
ReportInterface report=new ReportInterface();
// sanity check
// run the report
// MED: need a way of getting this session's data source
return report.run( HibernateSession.getDataSource(), ifeObj, params
);
}
catch ( Exception e )
{
throw new ReferenceCoreException( e );
}
Finallay
{
report=null;
}
}
我觉得如果我们将报表对象设置为null,那么报表对象和run方法返回的数组列表之间的连接应该被断开,GC可以回收数组列表堆内存。这是正确的吗?如果我在这里的理解有误,请纠正我。
还建议我们在report.run方法将数组列表返回到C#后是否有任何其他方法来清除数组列表?
还有为什么 AIX 服务器 IBM Java 没有抛出内存不足错误,Java 进程只是挂起?
【问题讨论】:
标签: java memory heap-memory aix