diff --git a/Controllers/AppController.cs b/Controllers/AppController.cs index a06567a..7abb42f 100644 --- a/Controllers/AppController.cs +++ b/Controllers/AppController.cs @@ -51,6 +51,13 @@ public void AddCustomer(Customer c) { cache.Add(c); } + + public void Clear() + { + cache.Clear(); + } + + public int Count => cache.Count; } class Processor @@ -61,6 +68,13 @@ public void ProcessTransaction(Customer customer) { cache.AddCustomer(customer); } + + public void ClearCache() + { + cache.Clear(); + } + + public int CacheCount => cache.Count; } [HttpGet] @@ -73,6 +87,9 @@ public ActionResult memleak(int kb) p.ProcessTransaction(new Customer(Guid.NewGuid().ToString())); } + // Clear cache after processing to prevent indefinite accumulation + p.ClearCache(); + return "success:memleak"; } @@ -105,10 +122,10 @@ public ActionResult sayhello() public ActionResult crash() { double bytesSize = 0; - while (true || bytesSize < 1_000_000) + while (bytesSize < 1_000_000) { bytesSize += 10 * 1024 * 1024; // 10MB - memoryHog.Add(new byte[10 * 1024 * 1024]); // Allocate 1MB + memoryHog.Add(new byte[10 * 1024 * 1024]); // Allocate 10MB } return "success:oomd";