views:

42

answers:

2

I'm looking at some code that I know has a memory leak and I think I know why. however; I am curious about the bloody details.

At the beginning of a request there is a call to session.OpenSession(); in order to get an ISession but at the end of the request there is no call session.Close(); and/or session.Dispose();

What objects are staying in memory? Are the "entities" hanging around? What features of NHibernate are being lost? Will these objects every get garbage collected?

A: 

hi ,You can use the singleton pattern

IBRAHIM ATAY
+1  A: 

If you don't close the session, all the entities referenced there, and all the supporting data structures stay there until it's garbage collected.

So, closing the session must be done at the end of the request, whether it was successful or not.

Diego Mijelshon