This project contains examples of code which will force the program into a state of common memory issues in .NET applications to be used when training debugging. The examples are designed to be used with the dotnet-dump tool to analyze memory dumps and identify the root cause of the memory issues.
Example: Memory Leak
Demonstrates a scenario where a list of objects is continuously populated without being cleared, leading to a memory leak because the objects are not being garbage collected. Use this simple example to learn how to identify how a large amount of objects look like by dumping statistics for the heap and inspecting objects.
Example: Threadpool starvation
Demonstrates a scenario where the thread pool continues to grow due to a long running operation being moved to the global queue and continuously taking in work on local queues. Use this example to learn how to identify thread pool starvation by inspecting the CLR threads.
Example: Blocked finalizer queue
Demonstrates a scenario where the finalizer queue is blocked due to a long running finalizer causing a memory leak. Use this example to identify a blocked finalizer queue by inspecting the finalizer queue CLR stack.
Example: Entity Framework cartesian explosion
Demonstrates a scenario where a simple EF query on a small amount of data is executed that returns a large number of rows, causing the application to use a lot of memory. Use this example to learn how to identify a cartesian explosion by inspecting the EF query and the objects in memory.
To run the examples, simply clone the repository and run the projects. The examples are designed to be simply run inside a console application. They will pause at a good point to take a memory dump and analyze.
- Install the dotnet-dump tool by running the following command:
dotnet tool install -g dotnet-dump
You can also visit the documentation from https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dump
- Run the application and get the process id by running the following command:
dotnet-dump ps
- Take a memory dump of the process by running the following command:
dotnet-dump collect -p <process id>
- Analyze the memory dump using the following command:
dotnet-dump analyze <dump file>
Run the examples and use the commands in the NetMemoryDebugCheatsheet.md to identify the root cause of the memory issue.
This project is licensed under the MIT License - see the LICENSE.md file for details.