且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

会话关闭后如何强制hibernate释放内存?

更新时间:2023-02-02 15:42:48

您可以尝试调用Session.clear来强制清除第一级缓存。请务必先调用Session.flush将任何挂起的更改写入数据库。如果修复了问题,那么我怀疑某些东西仍然存在对会话的引用,从而阻止缓存中的对象被垃圾收集。您可能需要获取程序的堆转储以跟踪泄漏。

You could try calling Session.clear to force a clear of the first-level cache. Be sure to call Session.flush first to write any pending changes to the database. If that "fixes" the problem, then I suspect something is still holding a reference to the session, preventing the objects in the cache from being garbage-collected. You may need to obtain a heap dump of your program to track down the leak.