microsoft / CLRInstrumentationEngine

The CLR Instrumentation Engine is a cooperation profiler that allows running multiple profiling extensions in the same process.
Other
91 stars 47 forks source link

Memory leaks on process shutdown #319

Open delmyers opened 3 years ago

delmyers commented 3 years ago

Our ref counting is indicating memory leaks on process shut down.

It looks like this is probably due to a circular reference between App Domains and the Module Infos contained therein. That circular reference is meant to be broken when we get a module unload callback, but that callback is not guaranteed on process shut down. We will likely also leak App Domain references on shut down because I don't think we are guaranteed to get a callback for that either. Essentially, I think all bets are off on callbacks during process exit.

We might need to have better memory leak detection. It probably wouldn't hurt to be a little better about circular references anyway. For example, there is no need to hold a ref-counted reference to the App Domain from the Module Info, since the App Domain should keep it alive.

jander-msft commented 3 years ago

142 might make that difficult to write a test with a real runtime if anything is released in the profiler's is deconstructor.