I'm trying to find a memory leak in a .NET 5.0 Web API application hosted in Kubernetes. I have read some tips and tricks and found a good advice here: https://www.tessferrandez.com/blog/2005/11/25/dumpheap-stat-explained.html
A good trick if you want to know where you leak and want to avoid looking through a lot of data that will be garbage collected soon is to run a stress-test, then induce a GC by calling GC.Collect(3), take a memory dump, then stress it a bit more, induce a GC again and take another memory dump and compare the objects on the heap.
I really don't want to create a special debugging method for the app and redeploy it to the test environment. So can I trigger garbage collection for Gen 2 from outside of the app?