Skip to content

How to deal with caches that are responsible for Dispose #552

Open
@pauldendulk

Description

@pauldendulk

I have a request for advise in a specific situation.

In our library we have a cache with a GetOrCreate method. This is not an uncommon patterns, see, for instance, MemoryCache.GetOrCreateAsync.

The IDisposableAnalyzer warns that the caller should Dispose (Warning IDISP001 Dispose created), but since it is a cache we want to reuse the object later. The cache itself should call Dispose() in a cleanup routine.

This is our method

var paint = vectorCache.GetOrCreatePaint(vectorStyle.Outline, opacity, PolygonRenderer.CreateSkPaint);

CreateSkPaint is a function that is called inside the GetOrCreatePaint method. Turning it into a lambda did not help. Is there another way we could organize our code to circumvent the warning?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions