{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/1395","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/1395/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/1395/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/1395/events","html_url":"https://github.com/dotnet/roslyn/pull/1395","id":63090308,"number":1395,"title":"Fix memory leaks in AnalyzerManager","user":{"login":"mavasani","id":10605811,"avatar_url":"https://avatars.githubusercontent.com/u/10605811?v=3","gravatar_id":"","url":"https://api.github.com/users/mavasani","html_url":"https://github.com/mavasani","followers_url":"https://api.github.com/users/mavasani/followers","following_url":"https://api.github.com/users/mavasani/following{/other_user}","gists_url":"https://api.github.com/users/mavasani/gists{/gist_id}","starred_url":"https://api.github.com/users/mavasani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mavasani/subscriptions","organizations_url":"https://api.github.com/users/mavasani/orgs","repos_url":"https://api.github.com/users/mavasani/repos","events_url":"https://api.github.com/users/mavasani/events{/privacy}","received_events_url":"https://api.github.com/users/mavasani/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Analyzers","name":"Area-Analyzers","color":"5319e7"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Bug","name":"Bug","color":"fc2929"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/cla-not-required","name":"cla-not-required","color":"90EE90"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-03-19T21:03:06Z","updated_at":"2015-03-20T01:46:05Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/dotnet/roslyn/pulls/1395","html_url":"https://github.com/dotnet/roslyn/pull/1395","diff_url":"https://github.com/dotnet/roslyn/pull/1395.diff","patch_url":"https://github.com/dotnet/roslyn/pull/1395.patch"},"body":"1) Statically created LocalizableString instances by analyzers were holding onto instances of AnalyzerExecutor (which holds onto the compilation on which it executes) for exception reporting, causing us to leak compilations in command line builds. Fixed this by making sure that we unregister these exception handlers during analyzer cleanup in CommonCompiler, we already did so for VisualStudioAnalyzer created in IDE.\r\n\r\n2) Switch AnalyzerManager._compilationScopeMap to have a ConditonalWeakTable value. Performance analysis showed that analyzers that capture the CompilationStartAnalysisContext in its RegisterCompilationStartAction via some lambda were rooting the compilation objects.\r\n\r\nAbove two changes got rid of all the static and dependent handles rooting compilations during command line builds, and I see a perceived reduction in memory used by VBCSCompiler during building Roslyn.\r\n\r\n3) Fix the IDE onAnalyzerException delegate to not capture project instance, but instead use the projectId. Otherwise, VSIX analyzers that live for lifetime of VS instance would leak compilations.\r\n\r\nWhile I was at it, I also got rid of functionality added to MetadataCache that was caching and re-using analyzer instances across AnalyzerFileReference instances, we had already decided to instead keep lifetime of analyzer instances bound by lifetime of owning AnalyzerFileReference.\r\n\r\n@heejaechang @tmeschter @pharring @srivatsn @JohnHamby can you please review?"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/83848069","html_url":"https://github.com/dotnet/roslyn/pull/1395#issuecomment-83848069","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/1395","id":83848069,"user":{"login":"mavasani","id":10605811,"avatar_url":"https://avatars.githubusercontent.com/u/10605811?v=3","gravatar_id":"","url":"https://api.github.com/users/mavasani","html_url":"https://github.com/mavasani","followers_url":"https://api.github.com/users/mavasani/followers","following_url":"https://api.github.com/users/mavasani/following{/other_user}","gists_url":"https://api.github.com/users/mavasani/gists{/gist_id}","starred_url":"https://api.github.com/users/mavasani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mavasani/subscriptions","organizations_url":"https://api.github.com/users/mavasani/orgs","repos_url":"https://api.github.com/users/mavasani/repos","events_url":"https://api.github.com/users/mavasani/events{/privacy}","received_events_url":"https://api.github.com/users/mavasani/received_events","type":"User","site_admin":false},"created_at":"2015-03-20T01:46:05Z","updated_at":"2015-03-20T01:46:05Z","body":"@heejaechang It would have been easier if there was a CompilationId, just like project and symbol ID!"}}