I'm having a huge problem with NHibernate and memory management.
I've made an ASP.NET application using NHibernate...Everything went perfect on small database. When the database became bigger (~2-3 GB)...the process w3wp.exe increases his memory a lot.
I'm very sure I'm closing the session at the end of each request because I've checked with the debugger.
Also the lazy is set to true.
A small example....to imagine exactly...I'm using a custom memberhsip provider in the authentication model...
So when I start the application and I'm redirected to the login page...w3wp.exe has 40 MB...ok...now when I log in and go to an empty page(just for test) the w3wp.exe process goes to 110MB....
For testing I've put only 2 users and 2 roles in the tables for authentication....the other tables has info which makes the database to be around 2-3 GB....
I'm very positive that I'm closing the session because I've checked with the debugger like I've said..
The code is:
Code:
public static void CloseSession()
{
HttpContext context = HttpContext.Current;
ISession currentSession = context.Items[CurrentSessionKey] as ISession;
if (currentSession == null)
{
// No current session
return;
}
currentSession.Close();
currentSession.Dispose();
context.Items.Remove(CurrentSessionKey);
}
The strange thing is that the memory goes up after I finish the above method to run (the target page is an empty one)...
The last lines from the log are:
2007-01-12 21:18:42,343 [5920] DEBUG NHibernate.Impl.SessionImpl [(null)] - disconnecting session
2007-01-12 21:18:42,343 [5920] DEBUG NHibernate.Connection.ConnectionProvider [(null)] - Closing connection
2007-01-12 21:18:42,343 [5920] DEBUG NHibernate.Impl.SessionImpl [(null)] - transaction completion
2007-01-12 21:18:42,343 [5920] DEBUG NHibernate.Impl.SessionImpl [(null)] - running ISession.Dispose()
2007-01-12 21:18:42,343 [5920] DEBUG NHibernate.Impl.BatcherImpl [(null)] - running BatcherImpl.Dispose(true)
2007-01-12 21:18:42,343 [5920] INFO NHibernate.Impl.SessionFactoryImpl [(null)] - Closing
Why it has this problem on huge databases even if I've made the test with login system which uses two tables (not all tables)?.....it's like the session stays in memory...I've forced the GC to delete it...I know you can't be 100% percent but is unlikely that at each scenario of accessing the database to grow so much the memory... I've "succedded" to reach 800 MB....I repeat..lazy is set to true...
It's so bad NHibernate on very big databases systems?!
Maybe I'm making a mistake somewhere...Please any idea?
Thx