File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
src/main/java/io/github/nettyplus/leakdetector/junit Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 1
1
package io .github .nettyplus .leakdetector .junit ;
2
2
3
3
import io .netty .util .ResourceLeakDetector .LeakListener ;
4
+ import java .lang .ref .WeakReference ;
4
5
import java .util .List ;
5
6
import java .util .concurrent .CopyOnWriteArrayList ;
6
7
@@ -21,6 +22,7 @@ public void assertZeroLeaks() {
21
22
}
22
23
23
24
public void assertZeroLeaks (String detail ) {
25
+ forceGc ();
24
26
if (!leaks .isEmpty ()) {
25
27
StringBuilder message = new StringBuilder ("Netty leaks: " );
26
28
if (detail != null ) {
@@ -32,6 +34,18 @@ public void assertZeroLeaks(String detail) {
32
34
}
33
35
}
34
36
37
+ private static void forceGc () {
38
+ WeakReference <Object > dummy = new WeakReference <>(new Object ());
39
+ while (dummy .get () != null ) {
40
+ System .gc ();
41
+ try {
42
+ Thread .sleep (250 );
43
+ } catch (InterruptedException e ) {
44
+ // ignore
45
+ }
46
+ }
47
+ }
48
+
35
49
public void reset () {
36
50
this .leaks .clear ();
37
51
}
You can’t perform that action at this time.
0 commit comments