Skip to content

Commit d570edb

Browse files
authored
Try harder to free memory for TString.testNoLeaks() (#281)
1 parent 83ef65b commit d570edb

File tree

1 file changed

+4
-7
lines changed
  • tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/types

1 file changed

+4
-7
lines changed

tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/types/TStringTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,22 @@ public void initializingTensorWithRawBytes() {
107107

108108
@Test
109109
public void testNoLeaks() throws Exception {
110-
System.gc();
111-
Thread.sleep(100);
112-
110+
// warm up and try to get all JIT compilation done to stabilize memory usage...
113111
for (int i = 0; i < 1000; i++) {
114112
TString.scalarOf(A_LARGE_STRING).close();
113+
System.gc();
115114
}
116115

117-
System.gc();
118-
Thread.sleep(100);
119116
long bytesBefore = Pointer.physicalBytes();
120117

121118
for (int i = 0; i < 1000; i++) {
122119
TString.scalarOf(A_LARGE_STRING).close();
120+
System.gc();
123121
}
124122

125-
System.gc();
126-
Thread.sleep(100);
127123
long bytesAfter = Pointer.physicalBytes();
128124

125+
// the difference should ideally be 0, but the JVM and TF Core may be holding onto some unrelated stuff...
129126
assertTrue(Math.abs(bytesAfter - bytesBefore) < 10_000_000);
130127
}
131128

0 commit comments

Comments
 (0)