Skip to content

Commit a5fdefc

Browse files
authored
fix: LRU cache memory leak. (#475)
Fixes #474
1 parent 8ff641b commit a5fdefc

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/shared/sdk-server/__tests__/cache/LruCache.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,19 @@ it('when it has been cleared', () => {
4646
expect(lruCache.get(i.toString())).toBeUndefined();
4747
}
4848

49-
// Fill the cache with integers again.
49+
// Fill the cache with integers in a different range.
5050
for (let i = 0; i < max; i += 1) {
51-
lruCache.set(`${i}`, i);
51+
lruCache.set(`${i + 100}`, i);
5252
}
5353

5454
// Check they are all there.
5555
for (let i = 0; i < max; i += 1) {
56-
expect(lruCache.get(i.toString())).toEqual(i);
56+
expect(lruCache.get(`${i + 100}`)).toEqual(i);
57+
}
58+
59+
// Check old keys don't associate with new values.
60+
for (let i = 0; i < max; i += 1) {
61+
expect(lruCache.get(i.toString())).toBeUndefined();
5762
}
5863
});
5964

packages/shared/sdk-server/src/cache/LruCache.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export default class LruCache {
110110
this.keys.fill(undefined);
111111
this.next.fill(0);
112112
this.prev.fill(0);
113+
this.keyMap.clear();
113114
}
114115

115116
private index() {

0 commit comments

Comments
 (0)