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

Popped items can't be garbage collected #7

Closed
pschiffmann opened this issue Jun 18, 2021 · 2 comments
Closed

Popped items can't be garbage collected #7

pschiffmann opened this issue Jun 18, 2021 · 2 comments
Labels
question Further information is requested

Comments

@pschiffmann
Copy link
Contributor

Hi!
I noticed that you only reduce this.length in pop() and clear(), but don't actually update ids. That means if I store large objects (e.g. DOM nodes) in the queue, they might not get garbage collected even if my code has no other references to them.
I don't know what the performance impact would be to always shrink ids. In any case, it should be safe to assign undefined to the unused indexes.

@mourner
Copy link
Owner

mourner commented Jun 18, 2021

Yes, this was an intentional change — see #1. I should probably add a note about this in the docs. There's also a shrink method that shrinks the arrays manually. Assigning undefined might have performance implications in case FlatQueue is used with numerical values since v8 and other JS engines heavily optimize numerical arrays and switch to "slow" mode whenever there's a hole or non-numerical value.

@mourner mourner added the question Further information is requested label Jun 18, 2021
@pschiffmann
Copy link
Contributor Author

Ah, I see. I updated #5 and added a comment about it.

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

No branches or pull requests

2 participants