dotnet / dotnet/aspnetcore

memory leak for asp.net core integration tests

Open
#48,047 17 comments 12 reactions 0 assignees View on GitHub
area-mvc investigate
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

When there are thousands of integration tests, the memory usage become pretty large. I finally located that the `WebApplicationBuilder` is not garbage collected. So there will be thousands of `WebApplicationBuilder` instances during the tests run.

### Expected Behavior

`WebApplicationBuilder` should be garbage collected after the `WebApplicationFactory` is disposed.

### Steps To Reproduce

I created a [github repo](https://github.com/chenbojian/aspnetcore-integration-test-memory-leak-poc) to demostrate the problem.

I am using the `WeakReference<>` type to check if an instance is garbage collected. Based on the result, you can find that the `WebApplicationFactory` is already garbage collected. But the `WebApplicationBuilder` still exists.

You can run `dotnet test` to see the failure.

### Exceptions (if any)

_No response_

### .NET Version

7.0.201

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.