Skip to content

Commit 5d69a0e

Browse files
author
Emile Joubert
committed
Prevent memory leak when churning through many connections
1 parent bb199c5 commit 5d69a0e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

.hgignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ rabbit\.snk$
3131
^build/
3232

3333
~$
34+
[Rr]e[Ss]harper
35+
\.user$
36+
\.orig$
3437

projects/client/RabbitMQ.Client/src/client/impl/ConnectionBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ public ConnectionBase(ConnectionFactory factory,
135135

136136
StartMainLoop();
137137
Open(insist);
138-
StartHeartbeatLoops();
138+
StartHeartbeatLoops();
139+
AppDomain.CurrentDomain.DomainUnload += HandleDomainUnload;
139140
}
140141

141142
public event ConnectionShutdownEventHandler ConnectionShutdown
@@ -592,8 +593,6 @@ public void NotifyHeartbeatThread()
592593

593594
public void MainLoop()
594595
{
595-
Thread.GetDomain().DomainUnload += new EventHandler(HandleDomainUnload);
596-
597596
bool shutdownCleanly = false;
598597
try
599598
{
@@ -899,7 +898,8 @@ public void OnShutdown()
899898
OnCallbackException(args);
900899
}
901900
}
902-
}
901+
}
902+
AppDomain.CurrentDomain.DomainUnload -= HandleDomainUnload;
903903
}
904904

905905
public void OnCallbackException(CallbackExceptionEventArgs args)

0 commit comments

Comments
 (0)