ObjectPool should support Dispose
See original GitHub issueCurrently the ObjectPool does not implement IDisposable
and thus does not dispose objects managed by the pool.
We didn’t do this in the past, because we don’t use the ObjectPool with Disposables, but it would be a blocker for anyone external who wanted to.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
ObjectPool.Dispose() is missing. (2021+)
The docs show two methods, Clear() and Dispose(). Clear simply calls the destroy() method on each of the pooled items.
Read more >Scripting API: Pool.ObjectPool_1.Dispose
Removes all pooled items. If the pool contains a destroy callback then it will be called for each item that is in the...
Read more >Object reuse with ObjectPool in ASP.NET Core
NET Core infrastructure that supports keeping a group of objects in memory for ... Items that are not returned to the pool will...
Read more >DefaultObjectPool do not dispose objects
We should use DefaultObjectPoolProvider.Create<T> , then it will return DisposableObjectPool instead of DefaultObjectPool : Console.
Read more >Object Pooling in Unity 2021+
Whenever you dispose your pool or there is no internal space to store the elements you return, the pool will destroy that element....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
See comment here: https://github.com/aspnet/Extensions/blob/master/src/ObjectPool/src/DisposableObjectPool.cs#L41
The pool will dispose an object that it “forgets”.
Our pool implementation is based on retaining some amount of items when they are returned to the pool. You can always lease as many objects as you want and return them - we’ll only keep a fixed number in the pool.
If the pool size is 10, and you lease 15 objects and then return them, we will keep 10, and dispose 5.
@gfoidl yep. Looks like this is done.
Is documentation enough here? If the object implements IDisposable, it seems it will use the DisposableObjectPool, there isn’t really a way to prevent that. Or is the suggestion to document that if you create an ObjectPool<T> with a disposable T it will be disposed? If so, XML docs are probably the best solution here since I don’t know that we have a narrative doc for this.