Do you have a memory leak using NHibernate?
Are you doing a lot of processing in a loop, get, process, save, repeat,?
Well, firstly it's not really a leak... it's how Nhibernate works, and seeing as a leak
indicates you're probably not using NHibernate remotely how it's supposed to be used...
But then again , so are we... I have a winforms application generating reports for lots of students in a row... Once processed I'm completely done with the student and not going back...
So I needed to flush everything out of the Nhibernate cache, both layer 1 and 2.
Now If you're going to use this realize it almost certainly means you're using Nhibernate incorrectly...
and you'd probably be better off just going back to Ado... more speed, less memory used...
But that said, here's how to flush it all
SuperFlushJcdcSessionFirstAndSecondCaches();
Ha Hah just kidding, here's the part you really want...
public void SuperFlushJcdcSessionFirstAndSecondCaches(
{
INHFactory eFolderDocFactory = ObjectFactory.GetNamedInstance<INHFactory>( "JCDC" );
ISessionFactory sessionFactory = eFolderDocFactory.GetFactory();
// FROM http://stackoverflow.com/questions/2660714/how-to-clear-the-entire-second-level-cache-in-nhibernate - EWB
sessionFactory.EvictQueries();
foreach ( var collectionMetadata in sessionFactory.GetAllCollectionMetadata() )
{ sessionFactory.EvictCollection( collectionMetadata.Key );
}
foreach ( var classMetadata in sessionFactory.GetAllClassMetadata() )
{ sessionFactory.EvictEntity( classMetadata.Key )
}
}
No comments:
Post a Comment