question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ObjectPool should support Dispose

See original GitHub issue

Currently 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:closed
  • Created 5 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rynowakcommented, Nov 5, 2019

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.

0reactions
analogrelaycommented, Nov 5, 2019

@gfoidl yep. Looks like this is done.

Better to do some documentation for this.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found