Nhibernate uses a lot of memory

2019-06-26 10:54发布

问题:

I've got fluent nhibernate in my application and I'm trying to locate the cause of high memory usage. (I say high, it's 60MB, but it's a web app and it's not very big) Unfortunately it looks like a lot of it is in unmanaged memory, so I started taking things out - and as soon as I took out any calls to nhibernate, the memory usage dropped to 11MB!! Why oh why would it be taking up so much memory? Especially, why would it be taking up unmanaged memory?

I've been 'Googling' this all day and all I can find are posts from people saying "NHibernate eats memory..." and answers that say "no it doesn't, there's no evidence". Are NHibernate people in denial about it?

回答1:

Possible reasons: NHibernate caching.

Check these articles:

  • http://nhforge.org/blogs/nhibernate/archive/2009/04/24/nhibernate-2nd-level-cache.aspx

  • http://nhforge.org/blogs/nhibernate/archive/2009/02/09/quickly-setting-up-and-using-nhibernate-s-second-level-cache.aspx

Keep in mind "more memory usage" shouldn't be "this is devil". I mean that some caching or other factors would increase overall performance if the machine hosting everything has enough resources.

You can use this free profiler too, so you can check what's "wasting" your memory - maybe it's not a waste of memory but a proper usage for performance optimization - :

  • http://www.eqatec.com/tools/profiler/