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

[fix][ml] Fix memory leak due to duplicated RangeCache value retain operations #23955

Merged
merged 4 commits into from
Feb 10, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add tests for refCnt after evinction
  • Loading branch information
BewareMyPower committed Feb 10, 2025
commit a1e97cadaeff1e7fc6864586d182d6adf68d2d3b
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,29 @@ public void customWeighter() {
@Test
public void customTimeExtraction() {
RangeCache<Integer, RefString> cache = new RangeCache<>(value -> value.s.length(), x -> x.s.length());
final Runnable assertRefCnt = () -> {
final var entries = cache.getRange(1, 4444);
for (var entry : entries) {
assertEquals(entry.refCnt(), 2);
entry.release();
}
};

cache.put(1, new RefString("1"));
cache.put(22, new RefString("22"));
cache.put(333, new RefString("333"));
cache.put(4444, new RefString("4444"));

assertRefCnt.run();
assertEquals(cache.getSize(), 10);
assertEquals(cache.getNumberOfEntries(), 4);

Pair<Integer, Long> evictedSize = cache.evictLEntriesBeforeTimestamp(3);
assertEquals(evictedSize.getRight().longValue(), 6);
assertEquals(evictedSize.getLeft().longValue(), 3);

assertEquals(cache.getSize(), 4);
assertEquals(cache.getNumberOfEntries(), 1);
assertRefCnt.run();
}

@Test
Expand Down Expand Up @@ -355,4 +363,4 @@ public void testGetKeyWithDifferentInstance() {
// the value should be found
assertEquals(s.s, "129");
}
}
}