From 9b5dbad7fb0fc1b16888f872ceab408fe4fc3a01 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 21:57:03 +0000 Subject: [PATCH 1/2] Initial plan From b5a490a42275ecce9ab233498f7b065bc1cfec7a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 22:01:53 +0000 Subject: [PATCH 2/2] Fix memory issues in crash and memleak endpoints Co-authored-by: mrsharm <68247673+mrsharm@users.noreply.github.com> --- Controllers/AppController.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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";