Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
.NET Core Exceptions memory leak repro
using System;
using System.Threading.Tasks;
namespace ConsoleApp2189
{
public static class Program
{
public static void Main(string[] args)
{
while (true)
{
Task.Run(() => TopLevel());
}
}
public static async Task<string> TopLevel()
{
try
{
return await A();
}
catch (Exception e)
{
var s = e.ToString();
// Do nothing - we're just interested in allocations
return s;
}
}
public static async Task<string> A() => await B();
public static async Task<string> B() => await C();
public static async Task<string> C() => await D();
public static async Task<string> D() => await E();
public static async Task<string> E() => await F();
public static async Task<string> F() => await G();
public static async Task<string> G() => await H();
public static async Task<string> H() => await I();
public static async Task<string> I() => await J();
public static async Task<string> J() => await K();
public static async Task<string> K() => await L();
public static async Task<string> L() => await M();
public static async Task<string> M() => await N();
public static async Task<string> N() => await O();
public static async Task<string> O() => await P();
public static async Task<string> P() => await Q();
public static async Task<string> Q() => await R();
public static async Task<string> R() => await S();
public static async Task<string> S() => await T();
public static async Task<string> T() => await U();
public static async Task<string> U() => await V();
public static async Task<string> V() => await W();
public static async Task<string> W() => await X();
public static async Task<string> X() => await Y();
public static async Task<string> Y() => await Z();
public static async Task<string> Z() => throw new Exception("Well this is isn't very efficient.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.