Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Controllers/AppController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public void AddCustomer(Customer c)
{
cache.Add(c);
}

public void Clear()
{
cache.Clear();
}

public int Count => cache.Count;
}

class Processor
Expand All @@ -61,6 +68,13 @@ public void ProcessTransaction(Customer customer)
{
cache.AddCustomer(customer);
}

public void ClearCache()
{
cache.Clear();
}

public int CacheCount => cache.Count;
}

[HttpGet]
Expand All @@ -73,6 +87,9 @@ public ActionResult<string> memleak(int kb)
p.ProcessTransaction(new Customer(Guid.NewGuid().ToString()));
}

// Clear cache after processing to prevent indefinite accumulation
p.ClearCache();

return "success:memleak";
}

Expand Down Expand Up @@ -105,10 +122,10 @@ public ActionResult<string> sayhello()
public ActionResult<string> 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";
Expand Down