Skip to content

Memory leak in unit tests #213

@ArnaudB88

Description

@ArnaudB88

Hi,

We use LightInject for many years in multiple big solutions in our company. A few weeks ago we noticed failing CI builds in Azure due to an out-of-memory exception on the build server (6GB RAM).
When debugging our tests locally, we also noticed a lineair increase in memory when executing our (2000 a 3000) unit tests.

After searching for a while, we noticed the problem is possibly due to the fact we create a ServiceProvider manually. This is needed for resolving the MediatR class:

        private void ConfigureContainer()
        {
            ContainerManager.Container.Register<IMediator, Mediator>();

            //Needed by MediatR (Not needed in AspNetCore projects since that uses the Host.UseLightInject())
            if (!ContainerManager.Container.AvailableServices.Any(sr => sr.ServiceType == typeof(IServiceProvider)))
                ((ServiceContainer)ContainerManager.Container).CreateServiceProvider(new ServiceCollection());
        }

I created a fork of your repo and added a separate unit test project with one test illustrating the memory leak:
ArnaudB88#1

I hope you can help us in finding a solution/bugfix.

Thanks!
Arnaud

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions