Cleanup on Session End

Sep 2, 2009 at 3:47 PM

Hello,

I have extended the generated application with an additional data provider. I followed here your schema for NHibernate. If probably will refactor somday later to use NHibernate mapping mechanism but since this is the first time I'm using NHibernate I skipped it (tight schedule). I also only heard of that in one of Radim's posts.

My Dao does access a proprietary data provider (basically a DLL) through Interop/COM. This DLL allocates about 30 MB memory. When I close my browser the webserver does not release the memory. I need to call a "Free" method on that DLL.

So my question is: where would I put this call (i.e. MedianSession.Free();)

Kind Regards

Benno

Coordinator
Sep 2, 2009 at 5:46 PM

Hi Benno

Maybe short description of Catharis NHibernate implementation will help you to find the answer for your COM stuff.

Factory == 1 Object per application. There is NHibernate Factory based on Singleton design pattern, which basically means - there is one Factory instance in the application lifetime.

Session == 1 object per request. Whenever there is an request - Factory is called to create the NHibernate request-based working environment -> called Session. This object is referenced in the Request.Items collection (and therefore is cleaned by GC when the request is finished)

Imagine that the Factory object is using 30 MB (only as an example). Then even when you close browser - the Application still lives. And therefore it still references the Factory object (as for example said 30MB large). And that could be an 'indicia' to your question.

By the way, one of the fastest ways how to restart application (and also release all referenced objects; until they are reinstantiated) is to make any change into the web.config file.

Maybe that could help

Enjoy Catharsis

Radim Köhler