memory leak for asp.net core integration tests
- 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
Assessment
This issue has not been assessed yet.