-
Notifications
You must be signed in to change notification settings - Fork 67
Make DependencyTableStore a real singleton #557
Conversation
{ | ||
lock (SyncRoot) | ||
{ | ||
if (instance == null) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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...
My apologies, the instance property already existed and I didn't need to panic merge this. |
This reverts commit bfe2567.
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. |
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. |
Ignore what i said about lock- lock is not involved except for 1st time. |
Fixes beta3 memory issue #554