Skip to content

Conversation

@gfoidl
Copy link
Member

@gfoidl gfoidl commented Feb 21, 2018

For discussion see #317
This is the variant Abstract base class, addressing #317 (comment)

Copy link
Member

@rynowak rynowak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this design change looks great!

@davidfowl
Copy link
Member

Yes, I prefer this to the dynamic code generation version.

public DefaultObjectPool(IPooledObjectPolicy<T> policy, int maximumRetained)
{
_policy = policy ?? throw new ArgumentNullException(nameof(policy));
_fastPolicy = policy as PooledObjectPolicy<T>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is worth a comment, explaining that this base class was introduced in 2.1 to avoid the interface call

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, now I added the comment above. Is the intention still clear or should I move the comment to this line?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@rynowak
Copy link
Member

rynowak commented Feb 21, 2018

I'm going to generate this whole class with emit next time you go on vacation

@rynowak rynowak merged commit 9943dd0 into dotnet:dev Feb 21, 2018
@gfoidl gfoidl deleted the objectpool-devirt-wo-ilcodgen branch February 21, 2018 16:28
@davidfowl
Copy link
Member

That settles it, I'm never going on vacation again.

eerhardt added a commit to eerhardt/machinelearning that referenced this pull request Apr 1, 2020
Accesses to this list are not thread-safe because we can be enumerating it on one thread (in Return) while another thread adds to it (in Create).

The list is unnecessary because the PredictionEngine will always be "rooted". Either it was being held in memory by someone who got the PredictionEngine from the pool, or it is being held by the ObjectPool itself. So it won't ever be GC'd, and the WeakReference is not doing anything.

Also, inherit from PooledObjectPolicy instead of IPooledObjectPolicy, so it can take the "fastPolicy" path in DefaultObjectPool. (See dotnet/extensions#318).

Fix dotnet#4981
eerhardt added a commit to dotnet/machinelearning that referenced this pull request Apr 2, 2020
Accesses to this list are not thread-safe because we can be enumerating it on one thread (in Return) while another thread adds to it (in Create).

The list is unnecessary because the PredictionEngine will always be "rooted". Either it was being held in memory by someone who got the PredictionEngine from the pool, or it is being held by the ObjectPool itself. So it won't ever be GC'd, and the WeakReference is not doing anything.

Also, inherit from PooledObjectPolicy instead of IPooledObjectPolicy, so it can take the "fastPolicy" path in DefaultObjectPool. (See dotnet/extensions#318).

Fix #4981
@ghost ghost locked as resolved and limited conversation to collaborators May 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants