When I save some entities with Session.Save, I noticed all object
states still live in the memory even if I flush and clear the session.

I used windbg and I saw ,the object states live in
NHibernate.Action.EntityInsertAction.states field. However I couldn't
understand why the object states still kept despite I cleared the
session. Then from windbg I saw the following relation by running !
gcroot

00000000029085f0(NHibernate.Impl.SessionImpl)->
  00000000029086f8(NHibernate.Engine.ActionQueue)->
  0000000002908b00(NHibernate.Engine.ActionQueue
+BeforeTransactionCompletionProcessQueue)->
 
0000000002908b20(System.Collections.Generic.List`1[[NHibernate.Action.BeforeTransactionCompletionProcessDelegate,
NHibernate]])->
  000000000290c5d0(System.Object[])->
 
000000000290c590(NHibernate.Action.BeforeTransactionCompletionProcessDelegate)-
>
  000000000290c060(NHibernate.Action.EntityInsertAction)


It is seen the EntityInsertAction is being hold by
BeforeTransactionCompletionProcessDelegate.

I check the NHibernate.Action.EntityAction type and saw

public virtual BeforeTransactionCompletionProcessDelegate
BeforeTransactionCompletionProcess
{
get
{
return new
BeforeTransactionCompletionProcessDelegate(this.BeforeTransactionCompletionProcessImpl);
}
}

Basically nhibernate keeps these delegates for interceptors and
because of this, the EntityAction object lives in the memory ("this"
pointer in above code).
However it is not so common that we have any listener for
BeforeTransactionCompletion. So we are keeping the object state's for
no reason. Look at same code for

public virtual AfterTransactionCompletionProcessDelegate
AfterTransactionCompletionProcess
{
get
{
if (!this.NeedsAfterTransactionCompletion())
{
return null;
}
return new
AfterTransactionCompletionProcessDelegate(this.AfterTransactionCompletionProcessImpl);
}
}

As you see it checks if there is any requirements . If not then
returns null. Same should be done for
BeforeTransactionCompletionProcessDelegate
. I can't believe how this bug is lived so far. It is causing a lot of
memory used for nothing.


I opened a ticket at https://nhibernate.jira.com/browse/NH-3046

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to