Java/C# smart pointer tests: Give GC more time to collect objects

This commit is contained in:
William S Fulton 2014-03-15 23:39:37 +00:00
commit 87963d2e68
6 changed files with 137 additions and 67 deletions

View file

@ -13,6 +13,16 @@ public class li_boost_shared_ptr_runme {
// Debugging flag
public final static boolean debug = false;
private static void WaitForGC()
{
System.gc();
System.runFinalization();
try {
java.lang.Thread.sleep(10);
} catch (java.lang.InterruptedException e) {
}
}
public static void main(String argv[])
{
if (debug)
@ -37,21 +47,20 @@ public class li_boost_shared_ptr_runme {
if (debug)
System.out.println("Nearly finished");
int countdown = 100;
while (true) {
System.gc();
System.runFinalization();
try {
java.lang.Thread.sleep(10);
} catch (java.lang.InterruptedException e) {
{
int countdown = 500;
int expectedCount = 1;
while (true) {
WaitForGC();
if (--countdown == 0)
break;
if (Klass.getTotal_count() == expectedCount) // Expect the one global variable (GlobalValue)
break;
}
if (--countdown == 0)
break;
if (Klass.getTotal_count() == 1) // Expect 1 instance - the one global variable (GlobalValue)
break;
};
if (Klass.getTotal_count() != 1)
throw new RuntimeException("Klass.total_count=" + Klass.getTotal_count());
int actualCount = Klass.getTotal_count();
if (actualCount != expectedCount)
throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount);
}
int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();
if (wrapper_count != li_boost_shared_ptr.getNOT_COUNTING())