Skip to content

Rethink Pool design  #28

@nickrobinson251

Description

@nickrobinson251

i noticed that Pool is currently providing two things, which i think it is confusing to combine (at least in the way they're currently combined):

  1. "permits": acting as a Semaphore to limit the maximum number of objects in use at a time
  2. "store": providing a collection of objects available for re-use

But note that the limit is on the "permits" (the number of objects in use), not on the "store" (the number of object available for re-use), on which there is no limit, e.g.

julia> pool = Pool{Int}(2);

julia> for i in 1:100
           x = acquire(() -> i, pool; forcenew=true)
           release(pool, x)
       end;

julia> length(pool.values)
100

I worry this could lead to a potential memory leak for users who do not realise that the "store" can grow arbitrarily in size and never be cleaned up.

I wonder if the size of the "store" should also be limited (for example, forcenew could force an eviction either always or if the collection is at capacity)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions