simpleinjector / SimpleInjector

An easy, flexible, and fast Dependency Injection library that promotes best practice to steer developers towards the pit of success.
https://simpleinjector.org
MIT License
1.21k stars 155 forks source link

What's best way to get .net 3.5 SimpleInjector Decorator Memory Leak bug fix? #995

Closed Zayik closed 2 months ago

Zayik commented 5 months ago

Problem: SimpleInjector 1.6 contains memory leak when using decorators. I'm stuck on legacy tools/hardware from both internal use, and 3rd party that cannot be upgraded to newer .net. Container is instantiated periodically based on user configurations. Programs have typical lifespans of weeks, thus causing memory leaks that get noticeably large (upwards of 4GB seen).

Example code that causes memory leak: container.Register<IAnimal, Dog>(); container.RegisterDecorator(typeof(IAnimal), typeof(AnimalHandler)); container.GetInstance().Speak();

Goal: Version of SimpleInjector that supports .net 3.5 and eliminates the decorator memory leak.

Questions: What is the recommended route to achieve this?

Thoughts:

  1. Pull down 3.1.1 and backport to .net 3.5.
  2. Find the equivalent change in 1.6 and make it. (I'm not entirely certain what that equivalent change would be.)

Any help/suggestions would be greatly appreciated.

dotnetjunkie commented 5 months ago

In the /src folder there is a changes.txt file. It has been abandoned after the release of v4.0.0, in favor of simply tracking changes in the Github release notes. That changes.txt contains information of v2.0.0 (information that isn't available elsewhere because Simple Injector was still on Codeplex back than, but that website no longer exists). The change list for v2.0 notes that a bug concerning a memory leak in decorators was fixed. This might be a starting point for you.

So perhaps you can find the bug fix in source control (as all former Codeplex commits were ported to the Github git repo). You can cherriepick this change in your custom branch that you took from the latest v1.x release. You can build your own Simple Injector version based on this. Note that you won't be able to sign the assembly, but that should typically not be an issue.

I hope this helps.