Java/C# smart pointer tests: Give GC more time to collect objects
This commit is contained in:
parent
785d93d9fb
commit
87963d2e68
6 changed files with 137 additions and 67 deletions
|
|
@ -6,6 +6,13 @@ public class runme
|
|||
// Debugging flag
|
||||
public static bool debug = false;
|
||||
|
||||
private static void WaitForGC()
|
||||
{
|
||||
System.GC.Collect();
|
||||
System.GC.WaitForPendingFinalizers();
|
||||
System.Threading.Thread.Sleep(10);
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
if (debug)
|
||||
|
|
@ -27,22 +34,24 @@ public class runme
|
|||
if (debug)
|
||||
Console.WriteLine("Nearly finished");
|
||||
|
||||
int countdown = 100;
|
||||
while (true) {
|
||||
System.GC.Collect();
|
||||
System.GC.WaitForPendingFinalizers();
|
||||
System.Threading.Thread.Sleep(10);
|
||||
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 ApplicationException("Klass.total_count=" + Klass.getTotal_count());
|
||||
{
|
||||
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;
|
||||
}
|
||||
int actualCount = Klass.getTotal_count();
|
||||
if (actualCount != expectedCount)
|
||||
throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount);
|
||||
}
|
||||
|
||||
int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();
|
||||
if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING)
|
||||
if (wrapper_count != 1) // Expect 1 instance - the one global variable (GlobalSmartValue)
|
||||
if (wrapper_count != 1) // Expect the one global variable (GlobalSmartValue)
|
||||
throw new ApplicationException("shared_ptr wrapper count=" + wrapper_count);
|
||||
|
||||
if (debug)
|
||||
|
|
|
|||
|
|
@ -20,18 +20,38 @@ public class li_std_auto_ptr_runme {
|
|||
throw new Exception("number of objects should be 2");
|
||||
|
||||
k1 = null;
|
||||
WaitForGC();
|
||||
|
||||
if (Klass.getTotal_count() != 1)
|
||||
throw new Exception("number of objects should be 1");
|
||||
{
|
||||
int countdown = 500;
|
||||
int expectedCount = 1;
|
||||
while (true) {
|
||||
WaitForGC();
|
||||
if (--countdown == 0)
|
||||
break;
|
||||
if (Klass.getTotal_count() == expectedCount)
|
||||
break;
|
||||
};
|
||||
int actualCount = Klass.getTotal_count();
|
||||
if (actualCount != expectedCount)
|
||||
throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount);
|
||||
}
|
||||
|
||||
if (k2.getLabel() != "second")
|
||||
throw new Exception("wrong object label");
|
||||
|
||||
k2 = null;
|
||||
WaitForGC();
|
||||
|
||||
if (Klass.getTotal_count() != 0)
|
||||
throw new Exception("no objects should be left");
|
||||
{
|
||||
int countdown = 500;
|
||||
int expectedCount = 0;
|
||||
while (true) {
|
||||
WaitForGC();
|
||||
if (--countdown == 0)
|
||||
break;
|
||||
if (Klass.getTotal_count() == expectedCount)
|
||||
break;
|
||||
}
|
||||
int actualCount = Klass.getTotal_count();
|
||||
if (actualCount != expectedCount)
|
||||
throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue