Sorry I wrote up the pseudocode from memory, I am sure we are not building session factories.. the method is more likely "BuildSession" .. I will correct and repost in the correct group!
From: [email protected] [mailto:[email protected]] On Behalf Of Ayende Rahien Sent: Thursday, February 17, 2011 6:59 AM To: [email protected] Subject: Re: [nhibernate-development] Session Management a) this isn't the place for those sort of questions b) you keep creating session factories, not sessions On Thu, Feb 17, 2011 at 2:40 PM, Ryan <[email protected]> wrote: I have an application that is growing in memory size with every hit to our NHibernate repository object and not ever releasing that memory. This has become very noticable since we've added database polling to the application.. very simple query bringing back very little data but growing the memory footprint with each hit. Please explain to me what is wrong with this pattern? //pseudocode Class NHibernateRepository Private _factory as ISessionFactory // Constructor injection handled with Windsor Public Sub New NHibernateRepository(ISessionFactory factory) _factory = factory End Sub Public Sub List(Of TEntity)(dc as DetachedCriteria) Using session as ISession = _factory.BuildSessionFactory() Return session.List(dc) End Using End Sub So my first thought is that the session object is not being released. So I moved the return outside of the using block (assigning the results to a local IList and returning that). No improvements. Next thought is that maybe I shouldn't be disposing of the session with every call.. if I want to do lazy loading an active session is needed after all. So I added a private Session property that only builds the from the session factory if one does not already exist. Private _session as ISession Private Readonly Property Session() If _session Is Nothing Then _session = _factory.BuildSessionFactory() End If Return _session End Property This appears to solve the problem with the growing memory. However I am getting other errors that a datareader has already been opened for an operation and needs to be closed before being reused. Maybe I need to work through these errors. I'm just wondering if I'm heading in the right direction. Thanks! No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.872 / Virus Database: 271.1.1/3448 - Release Date: 02/16/11 13:34:00
