Calculate correct lastRecords size
Motivation: ResourceLeakDetector records at most MAX_RECORDS+1 records Modifications: Make room before add to lastRecords Result: ResourceLeakDetector will record at most MAX_RECORDS records
This commit is contained in:
parent
c43e09da5a
commit
96e06aa74d
@ -364,18 +364,19 @@ public class ResourceLeakDetector<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void record0(Object hint, int recordsToSkip) {
|
private void record0(Object hint, int recordsToSkip) {
|
||||||
if (creationRecord != null) {
|
// Check MAX_RECORDS > 0 here to avoid similar check before remove from and add to lastRecords
|
||||||
|
if (creationRecord != null && MAX_RECORDS > 0) {
|
||||||
String value = newRecord(hint, recordsToSkip);
|
String value = newRecord(hint, recordsToSkip);
|
||||||
|
|
||||||
synchronized (lastRecords) {
|
synchronized (lastRecords) {
|
||||||
int size = lastRecords.size();
|
int size = lastRecords.size();
|
||||||
if (size == 0 || !lastRecords.getLast().equals(value)) {
|
if (size == 0 || !lastRecords.getLast().equals(value)) {
|
||||||
|
if (size >= MAX_RECORDS) {
|
||||||
|
lastRecords.removeFirst();
|
||||||
|
++removedRecords;
|
||||||
|
}
|
||||||
lastRecords.add(value);
|
lastRecords.add(value);
|
||||||
}
|
}
|
||||||
if (size > MAX_RECORDS) {
|
|
||||||
lastRecords.removeFirst();
|
|
||||||
++removedRecords;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user