我重複調用這段代碼片段,並且每次調用內存需求都會不斷增加。休眠內存泄漏
如何在每次調用時釋放內存?
final Session session = Hibernate.getSessionFactory().openSession();
try {
Transaction tx = session.getTransaction();
tx.begin();
final ProjectionList projList = Projections.projectionList();
projList.add(Projections.count("totalLinePrice"));
projList.add(Projections.sum("totalLinePrice"));
final Object[] sum = (Object[]) session
.createCriteria(OrderR.class)
.setProjection(projList)
.add(Restrictions.eq("shopId", getShopR().getId()))
.add(Restrictions.gt("dtime", ord.monthBackTime))
.uniqueResult();
ord.num = (int) sum[0];
ord.revenueTotal = (long) sum[1];
tx.commit();
} catch (HibernateException e) {
throw new Bug(e);
} finally {
session.flush();
session.clear();
session.close();
}