Skip to content

Commit 46b5b2c

Browse files
committed
Nullify the disposing components to prevent memory leaks due circular reference.
1 parent 6da4ae2 commit 46b5b2c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/NHibernate/Impl/AbstractSessionImpl.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ protected internal void SetClosed()
330330
{
331331
if (TransactionContext != null)
332332
TransactionContext.Dispose();
333+
TransactionContext = null;
333334
}
334335
catch (Exception)
335336
{

src/NHibernate/Transaction/AdoNetWithDistributedTransactionFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public class DistributedTransactionContext : ITransactionContext, IEnlistmentNot
9494
{
9595
public System.Transactions.Transaction AmbientTransation { get; set; }
9696
public bool ShouldCloseSessionOnDistributedTransactionCompleted { get; set; }
97-
private readonly ISessionImplementor sessionImplementor;
97+
private ISessionImplementor sessionImplementor;
9898
public bool IsInActiveTransaction;
9999

100100
public DistributedTransactionContext(ISessionImplementor sessionImplementor, System.Transactions.Transaction transaction)
@@ -178,6 +178,8 @@ public void Dispose()
178178
{
179179
if (AmbientTransation != null)
180180
AmbientTransation.Dispose();
181+
AmbientTransation = null;
182+
sessionImplementor = null;
181183
}
182184
}
183185
}

0 commit comments

Comments
 (0)