File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/types Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 2020import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
2121import static org .junit .jupiter .api .Assertions .assertEquals ;
2222import static org .junit .jupiter .api .Assertions .assertNotNull ;
23+ import static org .junit .jupiter .api .Assertions .assertTrue ;
2324
2425import java .nio .charset .StandardCharsets ;
26+ import org .bytedeco .javacpp .Pointer ;
2527import org .junit .jupiter .api .Test ;
2628import org .tensorflow .ndarray .NdArray ;
2729import org .tensorflow .ndarray .NdArrays ;
@@ -103,5 +105,30 @@ public void initializingTensorWithRawBytes() {
103105 }
104106 }
105107
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 ]);
106133 private static final String BABY_CHICK = "\uD83D \uDC25 " ;
107134}
You can’t perform that action at this time.
0 commit comments