Skip to content

Commit 937f0ab

Browse files
Merge ba23a02 into 3ca27f8
2 parents 3ca27f8 + ba23a02 commit 937f0ab

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Autofac/Core/Registration/DefaultRegisteredServicesTracker.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,18 @@ protected override void Dispose(bool disposing)
247247
registration.Dispose();
248248
}
249249

250+
// If we do not explicitly empty the ConcurrentBag that stores our registrations,
251+
// this will cause a memory leak due to threads holding a reference to the bag.
252+
// In netstandard2.0 the faster 'Clear' method is not available,
253+
// so we have do this manually. We'll use the faster method if it's available though.
254+
#if NETSTANDARD2_0
255+
while (_registrations.TryTake(out _))
256+
{
257+
}
258+
#else
259+
_registrations.Clear();
260+
#endif
261+
250262
base.Dispose(disposing);
251263
}
252264

0 commit comments

Comments
 (0)