Skip to content

Commit cc70c4c

Browse files
author
Niall Pemberton
committed
IO-161 Try to fix the OutOfMemoryError in FileCleaningTrackerTestCase were seeing in Continuum and Gump
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1002920 13f79535-47bb-0310-9956-ffa450edef68
1 parent a32a395 commit cc70c4c

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/test/org/apache/commons/io/FileCleaningTrackerTestCase.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.File;
2020
import java.io.RandomAccessFile;
2121
import java.lang.ref.ReferenceQueue;
22+
import java.lang.ref.SoftReference;
2223
import java.util.ArrayList;
2324
import java.util.List;
2425

@@ -280,11 +281,12 @@ public void testFileCleanerExitWhenFinished2() throws Exception {
280281
//-----------------------------------------------------------------------
281282
private void waitUntilTrackCount() throws Exception {
282283
int count = 0;
284+
SoftReference<?> ref = new SoftReference<Object>(new Object());
283285
while(theInstance.getTrackCount() != 0 && count++ < 5) {
284286
List<String> list = new ArrayList<String>();
285287
try {
286288
long i = 0;
287-
while (true && theInstance.getTrackCount() != 0) {
289+
while (ref.get() != null) {
288290
list.add("A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String " + (i++));
289291
}
290292
} catch (Throwable ignored) {
@@ -293,6 +295,7 @@ private void waitUntilTrackCount() throws Exception {
293295
list = null;
294296
System.gc();
295297
Thread.sleep(1000);
298+
ref = new SoftReference<Object>(new Object());
296299
}
297300
if (theInstance.getTrackCount() != 0) {
298301
throw new IllegalStateException("Your JVM is not releasing SoftReference, try running the testcase with less memory (-Xmx)");

0 commit comments

Comments
 (0)