Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document auto-shrinking behaviour of Dictionary #125

Open
Tortar opened this issue Aug 29, 2023 · 1 comment
Open

Document auto-shrinking behaviour of Dictionary #125

Tortar opened this issue Aug 29, 2023 · 1 comment

Comments

@Tortar
Copy link

Tortar commented Aug 29, 2023

This is an important property to me since it allows to solve problems as the one described in https://discourse.julialang.org/t/is-dict-shrinking-feature-planned/68681. Can it be documented as an advantage of Dictionary over Dict? Or can it even be roughly explained what is the heuristic used to do the automatic shrinkage in the docs?

E.g.

julia> using Dictionaries

julia> d = Dictionary(x => x for x in 1:10^6);

julia> Base.summarysize(d)
48777424

julia> for x in 1:10^6 delete!(d, x) end

julia> Base.summarysize(d)
272

julia> d = Dict(x => x for x in 1:10^6);

julia> Base.summarysize(d)
35651768

julia> for x in 1:10^6 delete!(d, x) end

julia> Base.summarysize(d)
35651768
@andyferris
Copy link
Owner

Yes, I did implement it this way but the reason I didn't advertise this is I wasn't 100% sure whether the underlying Vector actually relinquishes its memory when shrunk. (I have a vague recollection of this being mentioned a long, long time ago and don't know the current story). Does anyone know?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants