File tree 1 file changed +27
-0
lines changed
tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/types
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 20
20
import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
21
21
import static org .junit .jupiter .api .Assertions .assertEquals ;
22
22
import static org .junit .jupiter .api .Assertions .assertNotNull ;
23
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
23
24
24
25
import java .nio .charset .StandardCharsets ;
26
+ import org .bytedeco .javacpp .Pointer ;
25
27
import org .junit .jupiter .api .Test ;
26
28
import org .tensorflow .ndarray .NdArray ;
27
29
import org .tensorflow .ndarray .NdArrays ;
@@ -103,5 +105,30 @@ public void initializingTensorWithRawBytes() {
103
105
}
104
106
}
105
107
108
+ @ Test
109
+ public void testNoLeaks () throws Exception {
110
+ System .gc ();
111
+ Thread .sleep (100 );
112
+
113
+ for (int i = 0 ; i < 1000 ; i ++) {
114
+ TString .scalarOf (A_LARGE_STRING ).close ();
115
+ }
116
+
117
+ System .gc ();
118
+ Thread .sleep (100 );
119
+ long bytesBefore = Pointer .physicalBytes ();
120
+
121
+ for (int i = 0 ; i < 1000 ; i ++) {
122
+ TString .scalarOf (A_LARGE_STRING ).close ();
123
+ }
124
+
125
+ System .gc ();
126
+ Thread .sleep (100 );
127
+ long bytesAfter = Pointer .physicalBytes ();
128
+
129
+ assertTrue (Math .abs (bytesAfter - bytesBefore ) < 10_000_000 );
130
+ }
131
+
132
+ private static final String A_LARGE_STRING = new String (new byte [1_000_000 ]);
106
133
private static final String BABY_CHICK = "\uD83D \uDC25 " ;
107
134
}
You can’t perform that action at this time.
0 commit comments