Reference counted IDisposable #4273
Unanswered
wilbennett
asked this question in
Language Ideas
Replies: 1 comment 1 reply
-
If semantics are the most important for you, Roslyn's |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Allow implicit reference counting for IDisposable instances.
Consider the following:
I believe this to be an unnecessary restriction when implementing using blocks. All called methods must be finished with the "used" object on return.
This can be fixed by using reference counting.
Consider:
This approach can benefit a lot of use cases. For example, creating a pool of expensive objects can now be fairly trivial.
A pool class/service can contain a collection of expensive objects.
A consumer asks the class/service for an instance.
When the consumer finishes and the instance is disposed, it can be returned to the pool.
The benefit of this is the consumer can be written simply. It doesn't need to know about the pooling and doesn't need to do anything special. It just requests an instance and uses it.
Beta Was this translation helpful? Give feedback.
All reactions