C# Interview Question #192
An ASP.NET Core API is using too much memory. What would you investigate?
Senior .NET Practical Scenarios Senior Advanced
Quick Interview Answer
First use memory metrics, dumps, traces, and a profiler to determine what objects are consuming memory and whether usage is expected, retained, or leaking through references.
Detailed Explanation
First use memory metrics, dumps, traces, and a profiler to determine what objects are consuming memory and whether usage is expected, retained, or leaking through references.
Investigate large collections, unbounded caches, static references, singleton services holding request data, large JSON payloads, excessive object allocations, event subscriptions, undisposed resources, and loading entire database tables into memory.
For EF Core, check long-lived DbContext instances, unnecessary tracking, large Include graphs, and missing pagination.
The GC should not be blamed automatically. High memory usage often comes from application code retaining references to objects that are still reachable and therefore cannot be collected.