Reputation: 3539
I have noticed that the ServiceCollection on setting up a new asp.net core application has Microsoft.Extensions.ObjectPool.ObjectPoolProvider injected by the framework by default. Why is this the case and more importantly when are we supposed to use this and how.
A Google search on this yields no results on what is does and the documentation I can find on learn.microsoft.com just described the type and nothing else.
Upvotes: 1
Views: 3068
Reputation: 665
Object pools are typically used to reduce the overhead of creating/initialising new instances of objects (eg. database connection pool) or reducing the impact of releasing resources (eg. minimising garbage collection or preventing memory fragmentation of a heap)
It looks like the ObjectPool has been recently documented here: https://learn.microsoft.com/en-us/aspnet/core/performance/objectpool?view=aspnetcore-3.0
Heres an excerpt describing one example use: ”... the ASP.NET Core framework uses the object pool in some places to reuse StringBuilder instances. StringBuilder allocates and manages its own buffers to hold character data.”
In relation to your question about it being registered in the ioc container by default, it looks like it’s now been removed from the defaults in net core 3.0 - see this this PR: https://github.com/aspnet/AspNetCore/pull/6437 and announcement: https://github.com/aspnet/Announcements/issues/336 :-)
If your interested in implementation details, there’s a ton of info in this answer here: C# Object Pooling Pattern implementation
Upvotes: 1