NHibernate + ActiveRecord + PostgreSQL = 内存异常
我有一个 winforms C#.Net 2.0 系统,带有 ActiveRecord + NHibernate 与 PostgreSQL 9 数据库通信。 当用户打开系统时,通过一个新的SessionScope()开始与DB的通信。对于某些用户来说,它工作得很好...但对于其他用户来说,系统会生成内存异常,与 msdn 论坛中 Marcio 的问题相同: 链接。 我该如何解决这个问题?问题出在 NHibernate 上!当我尝试关闭 ISession 对象或尝试提交事务时,会发生该错误。
I have a system in winforms C#.Net 2.0 with ActiveRecord + NHibernate communicating with a PostgreSQL 9 database.
When user open the system, starts the communication with the DB by a new SessionScope(). For some users it works perfectly... but for others the system generates a memoryexception, identical to the problem of Marcio in msdn forum: link.
How can I solve this problem? The problem is in NHibernate! The error occurs when I try to close the ISession object or when I try to Commit the transaction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OutOfMemoryException 的根本原因可能位于您发布的代码之外。您只是遇到了内存泄漏,并且它可能发生在应用程序中的任何位置。尝试分配更多内存的代码会抛出异常,而不一定是导致内存泄漏的代码。使用内存分析器找出导致内存泄漏的原因。
然而,这个问题很可能是由于 NHibernate 中的一级缓存膨胀造成的。来自 SessionScope 文档:
An underlying reason for OutOfMemoryException can be outside of the code that you posted. You simply have a memory leak and it can be anywhere in your app. The exception will be thrown from the code that tries to allocate more memory, not necessarily from the code that causes memory leak. Use memory profiler to figure out what causes the memory leak.
It is very likely however that this issue is due to bloated 1st level cache in NHibernate. From SessionScope document: