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

SourceNode uses too much memory because of AnnotationList #1912

Closed
ewoutkramer opened this issue Nov 5, 2021 · 0 comments · Fixed by #1922
Closed

SourceNode uses too much memory because of AnnotationList #1912

ewoutkramer opened this issue Nov 5, 2021 · 0 comments · Fixed by #1922
Assignees

Comments

@ewoutkramer
Copy link
Member

Describe the bug
Much like #603 , SourceNode creates a new instance of a Lazy<AnnotationList> for each and every node in the SourceNode. Which can be many when dealing with big resources.

Expected behavior
We should not allocate a fresh instance of Lazy<T> but use the static Lazy.EnsureInitialized instead:

In DomNode.cs:

    private readonly Lazy<AnnotationList> _annotations = new Lazy<AnnotationList>(() => new AnnotationList());
    protected AnnotationList AnnotationsInternal { get { return _annotations.Value; } }

should be changed to:

     private AnnotationList _annotations = null;
     private AnnotationList AnnotationsInternal => LazyInitializer.EnsureInitialized(ref _annotations);

This might be worth doing with the ChildList property too (in the same file):

   protected List<T> ChildList = new List<T>();

Additional context
Reported by the FirelyServer team, marked as Firely Favorite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants