Code to support an article on why you should avoid C# events in ASPNET Core apps:
Avoid Using C# Events in ASP.NET Core Apps
See also: C# Advent of Code 2024
Pull down the code, cd into the LongRunningConsole, and execute dotnet run
. You'll see something like this:
Note that it starts out showing each line of 1000 iterations every second or so but quickly slows down such that by iteration 260000 it takes 15+ seconds per line. The leak isn't just causing memory problems, but other performance issues as all of the handlers that weren't cleaned up must still be considered with each event raised.