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 )
}
}
Thursday, March 27, 2014
Friday, March 7, 2014
Brace Matching Hotkeys in Visual Studio...
I'm sure most of you are know about the matching brace highlighting feature in Visual Studio...
If you double click to select a brace, it's matching brace is highlighted in the same color...
Great, awesome for the file types where it works.. but what about the file types where it DOESN'T work?
Here where my tip of the <however often I decide to add tips> comes in...
In any file, say a razor view, click next to a brace, hit <ctrl>, ]... It jumps to the matching brace...
Bam,
Darn handy.
(I use resharper and the resharper keyboard settings , so YMMV, etc)
Subscribe to:
Posts (Atom)