Search code examples
.netmemory-leaksasync-awaitowinazure-service-fabric

Memory usage for EventHandler<UnobservedTaskExceptionEventArgs>


During memory profiling of my application (.NET owin service hosted on top of service fabric) I noticed EventHandler<UnobservedTaskExceptionEventArgs> has 24 instances each has size 1880B, but inclusive size - which I take is the object + all references around 1.2GB.

I take it this is somehow related to exceptions in unawaited tasks. Can this be a culprint or is it a red herring - and also why it is in memory dump in first place ?


Solution

  • Turns out this is part of service fabric infrastructure. Statefull service replica hooks itself to Task.UnobservedTaskException for some internal monitoring. It also gracefully deregister itself. The memory allocated is this big because of state dictionaries associated with replica.