Skip to content

Commit cd155c4

Browse files
committed
Let GC collect the last stored value if the queue becomes empty
1 parent ce72d41 commit cd155c4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ export default class Queue {
4141
return;
4242
}
4343

44-
this.#head = this.#head.next;
45-
this.#size--;
44+
const next = current.next;
45+
if (next) {
46+
this.#head = next;
47+
this.#size--;
48+
} else {
49+
this.clear();
50+
}
4651
return current.value;
4752
}
4853

0 commit comments

Comments
 (0)