Skip to content
This repository has been archived by the owner on Jul 5, 2020. It is now read-only.

Make DependencyTableStore a real singleton #557

Merged
merged 1 commit into from
May 10, 2017
Merged

Conversation

lmolkova
Copy link
Member

@lmolkova lmolkova commented May 10, 2017

Fixes beta3 memory issue #554
image

@lmolkova lmolkova changed the title Make DependencyTableStore real singleton Make DependencyTableStore a real singleton May 10, 2017
{
lock (SyncRoot)
{
if (instance == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall, does C# suffer from problems with doubled checked locking the way that Java does?
Is there a reason not to just create the instance in the declaration and let the class loader handle it?

Copy link
Member Author

@lmolkova lmolkova May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C# needs doubled checking, see https://msdn.microsoft.com/en-us/library/ff650316.aspx

I do not know why initially this was implemented as singleton. If you say it's not needed, I'm fine to initialize instance once in ctor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not questioning the singleton, only the doubled checked locking for initialization instead of a static constructor call with the variable declaration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double checking is described in that article. Anyway I'm fine with @cijothomas PR #559. We should have it in the stable release

Copy link
Member

@dnduffy dnduffy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like changes but I'm going to merge this for now since I realize I merged a dependent PR and likely broke the build...

@dnduffy dnduffy merged commit bfe2567 into develop May 10, 2017
@dnduffy
Copy link
Member

dnduffy commented May 10, 2017

My apologies, the instance property already existed and I didn't need to panic merge this.
Sorry

cijothomas added a commit that referenced this pull request May 10, 2017
@cijothomas
Copy link
Contributor

This solves memory leak, but introduces a lock. Since this method is called multiple times within tracking of a single dependency, this can be perf overhead. i will slightly tweak this and submit new PR on top of this.

@lmolkova
Copy link
Member Author

lmolkova commented May 10, 2017

This solves memory leak, but introduces a lock. Since this method is called multiple times within tracking of a single dependency, this can be perf overhead.

I did not get this.

The first time Instance is called in DependencyTrackingTelemetryModule.InitializeForDiagnosticAndFrameworkEventSource it will create a new table. Even if there is some concurrency in creation, there will be no dead lock, just a lock during initialization.

After that Instance will always be there and there will be no lock at all. This is canonical multi-threaded singleton implementation.

@cijothomas
Copy link
Contributor

Ignore what i said about lock- lock is not involved except for 1st time.

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

Successfully merging this pull request may close these issues.

5 participants