Skip to content

Potential misuse #1

@camerondm9

Description

@camerondm9

Directly returning the KeyedLock.Entry is efficient (no extra GC pressure), but allows for potential misuse if someone keeps a reference to it. They could call Dispose multiple times (or none).

We should probably return a wrapper class instead, so we can throw an exception if Dispose is called a second time.

Not sure what to do if they aren't calling Dispose at all, then their locks will stay locked forever and cause a memory leak...

Alternative: make all fields internal (on KeyedLock.Entry and add an analyzer that warns about putting it in a variable instead of a direct using statement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions