Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible memory leak in Xaml generator #11465

Closed
Youssef1313 opened this issue Feb 25, 2023 · 0 comments · Fixed by #11466
Closed

Possible memory leak in Xaml generator #11465

Youssef1313 opened this issue Feb 25, 2023 · 0 comments · Fixed by #11466
Labels
area/code-generation Categorizes an issue or PR as relevant to code generation area/performance 📈 Categorizes an issue or PR as relevant to performance difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification

Comments

@Youssef1313
Copy link
Member

Youssef1313 commented Feb 25, 2023

Current behavior

public partial class XamlCodeGenerator : ISourceGenerator
{
private readonly GenerationRunInfoManager _generationRunInfoManager = new GenerationRunInfoManager();

internal class GenerationRunInfoManager
{
private List<GenerationRunInfo> _runs = new List<GenerationRunInfo>();

internal record GenerationRunInfo(GenerationRunInfoManager Manager, int AdditionalFilesHash)
{
private ConcurrentDictionary<string, GenerationRunFileInfo> _fileInfo = new();

internal record GenerationRunFileInfo(GenerationRunInfo RunInfo, string FileId)
{
private Dictionary<INamedTypeSymbol, int> _appliedTypes = new Dictionary<INamedTypeSymbol, int>();

  • XamlCodeGenerator holds a reference to GenerationRunInfoManager (this is alone is not good - generators should never have state)
  • GenerationRunInfoManager holds a reference to a list of GenerationRunInfo.
  • GenerationRunInfo holds a reference to ConcurrentDictionary<string, GenerationRunFileInfo>
  • GenerationRunFileInfo has a dictionary that keeps symbols alive, and thus keeps whole compilations alive.

This looks like a memory leak. I don't think we should keep all old compilations alive this way.

@Youssef1313 Youssef1313 added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. area/code-generation Categorizes an issue or PR as relevant to code generation area/performance 📈 Categorizes an issue or PR as relevant to performance labels Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/code-generation Categorizes an issue or PR as relevant to code generation area/performance 📈 Categorizes an issue or PR as relevant to performance difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant