• M
    Add a CodeAnalysis diagnostic for detecting memory leaks in implementation of... · 20070331
    manishv 提交于
    Add a CodeAnalysis diagnostic for detecting memory leaks in implementation of analyzers (DoNotStorePerCompilationDataOntoFields): Instance of a diagnostic analyzer might outlive the lifetime of compilation (when executed in the IDE). Hence, storing per-compilation data, such as symbols, into the fields of a diagnostic analyzer might cause stale compilations to stay alive and cause memory leaks. Instead, one should store this data on a separate type instantiatied in a compilation start action, registered using AnaylsisContext.RegisterCompilationStartActionName API. An instance of this type will be created per-compilation and it won't outlive compilation's lifetime, avoiding memory leaks.
    
    Analyzer implementation: Analyzer tracks all field declarations within analyzer types (marked with DiagnosticAnalyzerAttribute) and flags if it's variable type declaration has any type syntax descendant that binds to a type implementing ISymbol or has Compilation in its type chain.
    
    I have also added a few positive and negative tests for the diagnostic. (changeset 1394660)
    20070331
CodeAnalysisDiagnosticsResources.Designer.cs 15.2 KB