Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nhibernate does not release memory after session closes

Tags:

nhibernate

I am using NHibernate 2.2 with c# 3.5 and VS2008,

The problem is when I close the Nhibernate Session object, the memory is not released. even I call GC.Collect() after every close, but nothing is getting freed up

How can I force NHibernate to release the objects loaded in session when session is closed?

thanks

like image 407
iBoy Avatar asked Jan 04 '11 17:01

iBoy


2 Answers

Use Dispose instead of close. (Not only for Session, but for every object implementing IDisposable in .net)

like image 99
Paco Avatar answered Sep 28 '22 01:09

Paco


There are a number of things which could prevent garbage collection actually occurring even if you call GC.Collect();. For example if other objects which are still alive and in use are holding a reference to something you no longer want, then the object will be kept alive.

Also don't forget that a portion of the memory used will be the objects that NHibernate has returned fro the database for you.

like image 36
Trevor Pilley Avatar answered Sep 28 '22 00:09

Trevor Pilley