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

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

Open
pauldendulk opened this issue Dec 18, 2023 · 1 comment
Open

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

pauldendulk opened this issue Dec 18, 2023 · 1 comment

Comments

@pauldendulk
Copy link

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?

@pauldendulk
Copy link
Author

I am still interested in a reaction to this question. It looks like the attribute option would help, but that PR is from 2018. What are people using in the mean time? Is there another tool that I should use? I feel like I am missing something. Where is all the fun?

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

No branches or pull requests

1 participant