// Tests Finalize() and WaitForPendingFinalizers()
using System;
+using System.Runtime.CompilerServices;
public class Test
{
obj = new Dummy();
}
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public void RunTest()
{
obj = null;
- GC.Collect();
-
- GC.WaitForPendingFinalizers(); // makes sure Finalize() is called.
}
}
CreateObj temp = new CreateObj();
temp.RunTest();
+ GC.Collect();
+ GC.WaitForPendingFinalizers(); // makes sure Finalize() is called.
+ GC.Collect();
if (visited)
{
namespace DefaultNamespace {
using System;
+ using System.Runtime.CompilerServices;
internal class GetTotalMemory
{
// a discrepancy of more than 50 bytes should be investigated
public const int padding = 50;
- public static int Main(String [] args )
+ public static bool AllocAndDealloc(int i, int MB, long heapSizeBeforeAlloc)
{
+ byte[] bary = new byte[i*MB]; //allocate iMB memory
+ bary[0] = 1;
+ bary[i*MB-1] = 1;
+
+ long heapSizeAfterAlloc = GC.GetTotalMemory(false);
+ Console.WriteLine( "HeapSize after allocated {0} MB memory: {1}", i, heapSizeAfterAlloc);
+ if( (heapSizeAfterAlloc - heapSizeBeforeAlloc)+i*padding<= i*MB || (heapSizeAfterAlloc - heapSizeBeforeAlloc) > (i+1)*MB )
+ {
+ Console.WriteLine( "Test Failed" );
+ return false;
+ }
+ bary[0] = 2;
+ bary[i*MB-1] = 2;
+ bary = null;
+ return true;
+ }
+ public static int Main(String [] args )
+ {
int MB = 1024*1024;
int iRep = 0;
Console.WriteLine("Test should return with ExitCode 100 ...");
// clean up memory before measuring
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
long heapSizeBeforeAlloc = GC.GetTotalMemory(false);
Console.WriteLine( "HeapSize before allocating any memory: {0}", heapSizeBeforeAlloc );
- byte[] bary = new byte[1];
for(int i=1; i<=iRep; i++ )
{
- bary = new byte[i*MB]; //allocate iMB memory
- bary[0] = 1;
- bary[i*MB-1] = 1;
-
- long heapSizeAfterAlloc = GC.GetTotalMemory(false);
- Console.WriteLine( "HeapSize after allocated {0} MB memory: {1}", i, heapSizeAfterAlloc);
- if( (heapSizeAfterAlloc - heapSizeBeforeAlloc)+i*padding<= i*MB || (heapSizeAfterAlloc - heapSizeBeforeAlloc) > (i+1)*MB )
+ if(!AllocAndDealloc(i, MB, heapSizeBeforeAlloc))
{
- Console.WriteLine( "Test Failed" );
return 1;
}
- bary[0] = 2;
- bary[i*MB-1] = 2;
- bary = null;
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
heapSizeBeforeAlloc = GC.GetTotalMemory(false);
Console.WriteLine( "HeapSize after delete all objects: {0}", heapSizeBeforeAlloc );
-
}
Console.WriteLine( "Test Passed!" );
*/
using System;
+using System.Runtime.CompilerServices;
public class Test
{
}
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void RunTest2()
{
Dummy2 obj2 = new Dummy2();
//for (int i=0; i<5; i++) {
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
//}
GC.KeepAlive(obj); // will keep obj alive until this point
// Tests KeepAlive()
using System;
+using System.Runtime.CompilerServices;
public class Test
{
obj = new Dummy();
}
- public void RunTest()
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public void DestroyObj()
{
obj = null; // this will collect the obj even if we have KeepAlive()
+ }
+
+ public void RunTest()
+ {
+ DestroyObj();
+
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
GC.KeepAlive(obj); // will keep alive 'obj' till this point
}
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
foo(o); //Recursive call
// Tests SuppressFinalize()
using System;
+using System.Runtime.CompilerServices;
public class Test {
}
}
- public static int Main() {
-
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public static void RunTest()
+ {
Dummy obj1 = new Dummy();
-
GC.SuppressFinalize(obj1); // should not call the Finalizer() for obj1
obj1=null;
-
+ }
+
+ public static int Main()
+ {
+ RunTest();
+
GC.Collect();
-
GC.WaitForPendingFinalizers(); // call all Finalizers.
+ GC.Collect();
if(Dummy.visited == false) {
Console.WriteLine("Test for SuppressFinalize() passed!");
// Also tests the target of the handle.
using System;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
public class Test
copy = handle;
}
- public bool RunTest()
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public void DestroyObj()
{
- // ensuring that GC happens even with /debug mode
obj = null;
- GC.Collect();
+ }
+ public bool RunTest()
+ {
+ GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
bool ans1 = handle.IsAllocated;
bool ans2 = copy.IsAllocated;
// should not be collected.
using System;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
public class Test {
}
}
- public static int Main() {
-
- Dummy obj = new Dummy();
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public static void RunTest()
+ {
+ Dummy obj = new Dummy();
Console.WriteLine("Allocating a normal handle to object..");
GCHandle handle = GCHandle.Alloc(obj,GCHandleType.Normal); // Normal handle
// ensuring that GC happens even with /debug mode
obj=null;
+ }
+
+
+ public static int Main() {
+ RunTest();
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
if(Dummy.flag == 0) {
-
Console.WriteLine("Test for GCHandleType.Normal passed!");
return 100;
}
// will be collected.
using System;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
public class Test
GCHandle handle = GCHandle.Alloc(obj, GCHandleType.Weak);
}
- public bool RunTest()
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public void RunTest()
{
// ensuring that GC happens even with /debug mode
obj = null;
- GC.Collect();
-
- GC.WaitForPendingFinalizers();
-
- if (Dummy.flag == 99)
- {
- return true;
- }
- else
- {
- return false;
- }
}
}
public static int Main()
{
CreateObj temp = new CreateObj();
+ temp.RunTest();
+
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ GC.Collect();
- if (temp.RunTest())
+ if (Dummy.flag == 99)
{
Console.WriteLine("Test for GCHandleType.Weak passed!");
return 100;
using System;
using System.Collections.Generic;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// the class that holds the HandleCollectors
private int _numInstances = 100;
private const int deltaPercent = 10;
+
// ensures GC Collections occur when handle count exceeds maximum
private bool Case1()
{
GC.WaitForPendingFinalizers();
GC.Collect();
- HandleCollectorTest h;
int original = GC.CollectionCount(0);
+ HandleCollectorTest h;
+
// create objects and let them go out of scope
for (int i = 0; i < _numInstances; i++)
h = new HandleCollectorTest();
h = null;
+
GC.WaitForPendingFinalizers();
// Collection should not have occurred
for (int i = 0; i < _numInstances; i++)
{
new HandleCollectorTest();
+
GC.WaitForPendingFinalizers();
+
handleCount = HandleCollectorTest.Count;
//Note that the GC should occur when handle count is 101 but it will happen at anytime after a creation and we stick to the previous
//count to avoid error
using System;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
public class Test {
- public class Dummy {
-
+ public class Dummy
+ {
public static bool visited=false;
~Dummy() {
Console.WriteLine("In Finalize() of Dummy");
}
}
- public class CreateObj {
+ public class CreateObj
+ {
Dummy dummy1;
Dummy dummy2;
- public CreateObj() {
+ public CreateObj()
+ {
dummy1 = new Dummy();
dummy2 = new Dummy();
}
- public bool RunTest() {
-
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public void RunTest()
+ {
WeakReference weak1 = new WeakReference(dummy1);
GCHandle handle = GCHandle.Alloc(dummy1,GCHandleType.Normal); // Strong Reference
// ensuring that GC happens even with /debug mode
dummy1=null;
dummy2=null;
-
- GC.Collect();
- GC.WaitForPendingFinalizers();
-
- if(Dummy.visited == true)
- return true;
- else
- return false;
}
}
- public static int Main() {
-
+ public static int Main()
+ {
CreateObj temp = new CreateObj();
- bool passed = temp.RunTest();
+ temp.RunTest();
+
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ GC.Collect();
- if(passed) {
+ if (Dummy.visited)
+ {
Console.WriteLine("Test for WeakReference.Finalize() passed!");
return 100;
}
- else {
+ else
+ {
Console.WriteLine("Test for WeakReference.Finalize() failed!");
return 1;
}
using System;
using System.IO;
+using System.Runtime.CompilerServices;
public class Test {
obj = new Dummy();
}
- public bool RunTest() {
-
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public void RunTest() {
obj=null;
- GC.Collect();
-
- GC.WaitForPendingFinalizers(); // makes sure Finalize() is called.
-
- return Dummy.visited;
-
}
}
******************* END *****************************");
}
+ temp.RunTest();
- if (temp.RunTest()) {
+ GC.Collect();
+ GC.WaitForPendingFinalizers(); // makes sure Finalize() is called.
+ GC.Collect();
+
+
+ if (Dummy.visited)
+ {
Console.WriteLine("Test for Finalize() & WaitForPendingFinalizers() passed!");
return 100;
}
// Tests Finalize() on array of objects
using System;
+using System.Runtime.CompilerServices;
+
+public class Test
+{
+ public class Dummy
+ {
+ public static int count=0;
+ ~Dummy()
+ {
+ count++;
+ }
+ }
+
+ public class CreateObj
+ {
+ public Dummy[] obj;
+
+ public CreateObj() {
+ obj = new Dummy[10000];
+ for(int i=0;i<10000;i++) {
+ obj[i] = new Dummy();
+ }
+ }
+
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public void RunTest()
+ {
+ obj=null; // making sure collect is called even with /debug
+ }
+ }
+
+ public static int Main() {
+ CreateObj temp = new CreateObj();
+ temp.RunTest();
+
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ GC.Collect();
-public class Test {
-
- public class Dummy {
- public static int count=0;
- ~Dummy() {
- count++;
- }
- }
-
- public class CreateObj {
- public Dummy[] obj;
-
- public CreateObj() {
-
- obj = new Dummy[10000];
- for(int i=0;i<10000;i++) {
- obj[i] = new Dummy();
- }
- }
-
- public bool RunTest() {
- obj=null; // making sure collect is called even with /debug
- GC.Collect();
- GC.WaitForPendingFinalizers();
-
- if(Dummy.count == 10000) { // all objects in array finalized!
- return true;
- }
- else {
- return false;
- }
- }
- }
-
- public static int Main() {
-
- CreateObj temp = new CreateObj();
-
- if (temp.RunTest())
+ if (Dummy.count == 10000) // all objects in array finalized!
{
Console.WriteLine("Test for Finalize() for array of objects passed!");
return 100;
return 1;
}
- }
+ }
}
using System;
using System.Threading;
+using System.Runtime.CompilerServices;
public class Test {
- public class Dummy {
- public static int count=0;
- ~Dummy() {
- count++;
- Thread.Sleep(1000);
- }
- }
-
- public class CreateObj {
- public Dummy[] obj;
- public int ExitCode = 0;
-
- public CreateObj() {
- obj = new Dummy[10];
-
- for(int i=0;i<10;i++) {
- obj[i] = new Dummy();
- }
- }
-
- public void RunTest() {
-
- obj=null; // making sure collect is called even with /debug
- GC.Collect();
- GC.WaitForPendingFinalizers();
-
- if(Dummy.count == 10) { // all objects in array finalized!
- ExitCode = 100;
- //Console.WriteLine("Test for Finalize() for array of objects passed!");
- }
- else {
- ExitCode = 1;
- //Console.WriteLine("Test for Finalize() for array of objects failed!");
- }
- }
- }
-
- public static int Main() {
- CreateObj temp = new CreateObj();
- temp.RunTest();
-
- if(temp.ExitCode==100)
- Console.WriteLine("Test for Finalize() for array of objects passed!");
- else
- Console.WriteLine("Test for Finalize() for array of objects failed!");
- return temp.ExitCode;
- }
+ public class Dummy {
+ public static int count=0;
+ ~Dummy() {
+ count++;
+ Thread.Sleep(1000);
+ }
+ }
+
+ public class CreateObj {
+ public Dummy[] obj;
+ public int ExitCode = 0;
+
+ public CreateObj() {
+ obj = new Dummy[10];
+
+ for(int i=0;i<10;i++) {
+ obj[i] = new Dummy();
+ }
+ }
+
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public void RunTest() {
+ obj=null; // making sure collect is called even with /debug
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ }
+ }
+
+ public static int Main() {
+ CreateObj temp = new CreateObj();
+ temp.RunTest();
+
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ GC.Collect();
+
+ if (Dummy.count == 10)
+ Console.WriteLine("Test for Finalize() for array of objects passed!");
+ else
+ Console.WriteLine("Test for Finalize() for array of objects failed!");
+ return temp.ExitCode;
+ }
}
// Tests Finalize() and WaitForPendingFinalizers()
using System;
+using System.Runtime.CompilerServices;
public class Test
{
public class Dummy
{
- public static bool visited;
+ public static bool visited=false;
~Dummy()
{
obj = new Dummy();
}
- public bool RunTest()
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ public void RunTest()
{
obj=null;
- GC.Collect();
-
- GC.WaitForPendingFinalizers(); // makes sure Finalize() is called.
-
- return Dummy.visited;
}
}
public static int Main()
{
CreateObj temp = new CreateObj();
+ temp.RunTest();
+
+ GC.Collect();
+ GC.WaitForPendingFinalizers(); // makes sure Finalize() is called.
+ GC.Collect();
- if (temp.RunTest())
+ if (Dummy.visited)
{
Console.WriteLine("Test Passed");
return 100;
// Tests Exception handling in Finalize()
using System;
+using System.Runtime.CompilerServices;
public class Test {
- public class List {
- public int val;
- public List next;
- }
- public class Dummy {
+ public class List {
+ public int val;
+ public List next;
+ }
- public static bool visited;
-
- ~Dummy() {
- List lst = new List();
- Console.WriteLine("In Finalize() of Dummy");
- try {
- Console.WriteLine(lst.next.val); // should throw nullreference exception
- } catch(NullReferenceException) {
+ public class Dummy {
+ public static bool visited;
+
+ ~Dummy() {
+ List lst = new List();
+ Console.WriteLine("In Finalize() of Dummy");
+ try {
+ Console.WriteLine(lst.next.val); // should throw nullreference exception
+ } catch(NullReferenceException) {
Console.WriteLine("Caught NullReferenceException in Finalize()");
visited=true;
- }
-
-
- }
- }
+ }
+ }
+ }
- public class CreateObj {
- public Dummy obj;
+ public class CreateObj {
+ public Dummy obj;
- public CreateObj() {
- obj = new Dummy();
- }
+ public CreateObj() {
+ obj = new Dummy();
+ }
- public bool RunTest() {
- obj=null;
- GC.Collect();
-
- GC.WaitForPendingFinalizers(); // makes sure Finalize() is called.
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public void RunTest() {
+ obj=null;
+ }
+ }
- if(Dummy.visited == true) {
- return true;
- }
- else {
- return false;
- }
- }
- }
+ public static int Main() {
- public static int Main() {
+ CreateObj temp= new CreateObj();
+ temp.RunTest();
- CreateObj temp= new CreateObj();
+ GC.Collect();
+ GC.WaitForPendingFinalizers(); // makes sure Finalize() is called.
+ GC.Collect();
- if (temp.RunTest())
+ if (Dummy.visited)
{
Console.WriteLine("Test for Exception handling in Finalize() passed!");
return 100;
Console.WriteLine("Test for Exception handling in Finalize() failed!");
return 1;
}
-
-
- }
+
+
+ }
}
// Tests Finalize() with Inheritance
using System;
+using System.Runtime.CompilerServices;
namespace One
{
d = new D();
}
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public bool RunTest()
{
A a = c;
{
CreateObj temp = new CreateObj();
- if (temp.RunTest())
+ temp.RunTest();
+
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+
+ if (C.count == 2)
{
Console.WriteLine("Test Passed");
return 100;
using System;
using System.Threading;
+using System.Runtime.CompilerServices;
public class Test {
obj=new Dummy();
}
- public bool RunTest()
+ public void RunTest()
{
obj=null;
- GC.Collect();
-
- GC.WaitForPendingFinalizers(); // makes sure Finalize() is called.
-
- return Dummy.visited;
}
}
- public static int Main() {
-
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ public static void AllocAndDealloc()
+ {
CreateObj temp = new CreateObj();
+ temp.RunTest();
+ }
+
+ public static int Main()
+ {
+ AllocAndDealloc();
+
+ GC.Collect();
+ GC.WaitForPendingFinalizers(); // makes sure Finalize() is called.
+ GC.Collect();
- if (temp.RunTest())
+ if (Dummy.visited)
{
Console.WriteLine("Test Passed");
return 100;
temp1 = GCUtil.GetTarget(handle);
Console.WriteLine(temp1);
+
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
temp2 = GCUtil.GetTarget(handle);
Console.WriteLine(temp2);
// See the LICENSE file in the project root for more information.
using System;
+using System.Runtime.CompilerServices;
internal class List
{
CreateLargeObjects();
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
}
//Large Object Collection (half array)
CreateLargeObjectsHalf();
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
for(long i = 0; i < iterations; i++)
{
CreateLargeObjectsHalf();
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
}
//Promote from Gen1 to Gen2
SmallGC [] sgc;
sgc = new SmallGC [LOOP];
+
for (int j = 0; j < LOOP; j++)
sgc[j] = new SmallGC(0);
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
for(long i = 0; i < iterations; i++)
{
}
}
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public static List PopulateList(int len)
{
if (len == 0) return null;
}
return Node;
}
+
public static int ValidateList(List First, int len)
{
List tmp1 = First;
}
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void CreateLargeObjects()
{
LargeGC [] lgc;
lgc[i] = new LargeGC();
}
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void CreateLargeObjectsHalf()
{
LargeGC [] lgc;
using System;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Collections.Generic;
}
- // releases references to allocated objects
- // times GC.Collect()
- // if objects are finalizable, also times GC.WaitForPendingFinalizers()
- public void Deallocate()
+ public bool ClearList()
{
- bool finalizable = false;
-
if (m_list != null)
{
- finalizable = ( (m_list.Count > 0) && (m_list[0] is FNode));
m_list.Clear();
m_list = null;
+ return ( (m_list.Count > 0) && (m_list[0] is FNode));
}
+ return false;
+ }
+
+
+ // releases references to allocated objects
+ // times GC.Collect()
+ // if objects are finalizable, also times GC.WaitForPendingFinalizers()
+ public void Deallocate()
+ {
+ bool finalizable = ClearList();
GC.Collect();
if (finalizable)
{
GC.WaitForPendingFinalizers();
+ GC.Collect();
}
}
namespace DefaultNamespace {
using System;
+ using System.Runtime.CompilerServices;
using System.Collections.Generic;
internal class BaseFinal
//Console.WriteLine("after all objects were created, the heapsize is " + GC.GetTotalMemory(false));
}
- public bool RunTest()
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public void DestroyNode()
{
obj = null;
+ }
- GC.Collect();
- GC.WaitForPendingFinalizers();
- GC.Collect();
-
- Console.Write(BNode.icFinalNode);
- Console.WriteLine(" Nodes were finalized and resurrected.");
- //Console.WriteLine("after all objects were deleted and resurrected in Finalize() , the heapsize is " + GC.GetTotalMemory(false));
-
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public void ResurrectNodes()
+ {
for(int i=0; i< BNode.rlNode.Count; i++)
{
BNode oldNode = (BNode)BNode.rlNode[ i ];
oldNode = null;
BNode.rlNode[ i ] = null;
}
+ }
+
+ public bool RunTest()
+ {
+ DestroyNode();
+
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ GC.Collect();
+
+ Console.Write(BNode.icFinalNode);
+ Console.WriteLine(" Nodes were finalized and resurrected.");
+ //Console.WriteLine("after all objects were deleted and resurrected in Finalize() , the heapsize is " + GC.GetTotalMemory(false));
+
+ ResurrectNodes();
GC.Collect();
GC.WaitForPendingFinalizers();
}
+ [MethodImpl(MethodImplOptions.NoInlining)]
public void MakeLeak(int iRep)
{
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
//do a second GC collect since some nodes may have been still alive at the time of first collect
GC.Collect();
namespace NStruct {
using System;
+ using System.Runtime.CompilerServices;
internal class FinalNStruct
{
- public static STRMAP[] CreateObj(int iObj)
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public static void CreateObj(int iObj)
{
-
STRMAP []strmap = new STRMAP[iObj];
for (int i=0; i< iObj; i++ ) //allocate 3100KB
{
strmap[i] = new STRMAP();
}
- return strmap;
-
- }
-
- public static bool RunTest(int iObj,STRMAP []strmap)
- {
-
for( int i=0; i< iObj; i++ )
{
strmap[i] = null;
}
+ }
+ public static bool RunTest()
+ {
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
return ( FinalizeCount.icFinal == FinalizeCount.icCreat );
-
}
public static int Main(String [] args){
-
int iObj = 100;
- STRMAP []strmaptemp;
Console.WriteLine("Test should return with ExitCode 100 ...");
- strmaptemp = CreateObj(iObj);
- if (RunTest(iObj,strmaptemp))
+ CreateObj(iObj);
+
+ if (RunTest())
{
Console.WriteLine( "Created objects number is same with finalized objects." );
Console.WriteLine( "Test Passed !" );
namespace NStruct {
using System;
+ using System.Runtime.CompilerServices;
internal class NStructTun
{
#pragma warning disable 0414
private STRMAP Strmap;
#pragma warning restore 0414
+
public CreateObj(int Rep)
{
for( int i=0; i< Rep; i++ )
{
Strmap = new STRMAP();
}
- }
-
- public bool RunTest()
+ }
+
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public void DeleteStrmap()
{
Strmap=null;
+ }
+ public bool RunTest()
+ {
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
namespace DefaultNamespace {
using System;
+ using System.Runtime.CompilerServices;
public class FragMan
{
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
if (FragNode.Finalized == 0)
{
public FragMan( )
{
- buildTree( );
+ buildTree();
fnM = CvA_FNodes[12];
CvA_FNodes = null;
enumNode( fnM );
}
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public void buildTree( )
{
CvA_FNodes = new FragNode[26];
namespace LGen {
using System;
+ using System.Runtime.CompilerServices;
public class LeakGen
{
}
}
-
public bool runTest(int iRep, int iObj)
{
}
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public void MakeLeak(int iObj)
{
int [] mem;
using System;
using System.Collections.Generic;
+ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+
internal class NDPinFinal
{
internal Object p;
}
}
+
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public static void RemoveN()
+ {
+ m_n = null;
+ }
+
+
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public static void RemovePinList(int iObj)
+ {
+ for ( int i=0; i< iObj; i++ )
+ {
+ pinList[i] = null;
+ }
+ }
+
+
public static bool RunTest(int iObj)
{
return false;
}
- m_n = null;
+ RemoveN();
+
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
- for( int i=0; i< iObj; i++ )
- {
- pinList[i] = null;
- }
+ RemovePinList(iObj);
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
if( cFinalObj == cCreatObj )
{
namespace App {
using System;
- using System.Reflection;
using System.Collections.Generic;
+ using System.Reflection;
+ using System.Runtime.CompilerServices;
class ReflectObj
{
}
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public void CreateMoreObj()
{
rtype = new Type[0];
namespace DefaultNamespace {
using System;
+ using System.Runtime.CompilerServices;
internal class Continue
public class CreateObj
{
BNode obj;
+
#pragma warning restore 0414
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public CreateObj()
{
Continue mv_Obj = new Continue();
Console.WriteLine(" Nodes were created.");
}
-
- public bool RunTest()
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public void DestroyObj()
{
obj = null;
- GC.Collect();
- GC.WaitForPendingFinalizers();
- GC.Collect();
+ }
- Console.Write(BNode.icFinalNode);
- Console.WriteLine(" Nodes were finalized and resurrected.");
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public void ResurrectNodes()
+ {
for (int i = 0; i < BNode.rlNodeCount; i++)
{
BNode oldNode = (BNode)BNode.rlNode[i];
oldNode = null;
BNode.rlNode[ i ] = null;
}
+ }
+
+ public bool RunTest()
+ {
+ DestroyObj();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
- return ( BNode.icCreateNode == BNode.icFinalNode );
+ Console.Write(BNode.icFinalNode);
+ Console.WriteLine(" Nodes were finalized and resurrected.");
- }
+ ResurrectNodes();
+
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ GC.Collect();
+ return ( BNode.icCreateNode == BNode.icFinalNode );
+ }
}
+
public static int Main()
{
namespace DefaultNamespace {
using System;
+ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
internal class RootMem
internal static GCHandle [] root;
internal static int n;
+
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public static void AllocRoot()
+ {
+ }
+
public static int Main( String [] args )
{
int iSize = 1000;
rm_obj = new RootMem( n );
root[n] = GCHandle.Alloc(rm_obj );
}
- //Console.WriteLine("After save objects to Root and before GCed: "+GC.GetTotalMemory(false) );
+
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
- //Console.WriteLine("After save objects to Root and after GCed: "+GC.GetTotalMemory(false) );
Object v;
for( int i=0; i< iSize; i++)
{
v = ( root[i]) ;
}
- //Console.WriteLine("After Get objects from root and before GCed: "+GC.GetTotalMemory(false) );
+
GC.Collect();
- //Console.WriteLine("After Get objects from root and after GCed: "+GC.GetTotalMemory(false) );
for( int i=0; i<iSize; i++ )
{
root[i].Free();
}
- //Console.WriteLine("After free root and before GCed: "+GC.GetTotalMemory(false) );
+
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
- //Console.WriteLine("After free root and after GCed: "+GC.GetTotalMemory(false) );
+
try
{
for( int i=0; i<iSize; i++ )
//Console.WriteLine("after number {0} singlink is set: {1}", i, GC.GetTotalMemory(false) );
Delete();
+
+ GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
}
//Console.WriteLine("total allocated memory: {0}", GC.GetTotalMemory(false));
namespace DefaultNamespace {
using System;
using System.Collections.Generic;
+ using System.Runtime.CompilerServices;
internal class CreateObj
{
return result;
}
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public void DeleteObj(int iObj,int iSwitch)
{
for( int i= 0; i< iObj; i++ )
using System;
+using System.Runtime.CompilerServices;
namespace LargeObjectTest
{
{
public static int ExitCode = -1;
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
+ public static bool AllocAndCollect(int loop)
+ {
+ LargeObject largeobj;
+ try
+ {
+ largeobj = new LargeObject();
+ TestLibrary.Logging.WriteLine("Allocated LargeObject");
+ }
+ catch (Exception e)
+ {
+ TestLibrary.Logging.WriteLine("Failure to allocate at loop {0}\n", loop);
+ TestLibrary.Logging.WriteLine("Caught Exception: {0}", e);
+ return false;
+ }
+
+ largeobj = null;
+ return true;
+ }
+
public static int Main()
{
int loop = 0;
- LargeObject largeobj;
TestLibrary.Logging.WriteLine("Test should pass with ExitCode 100\n");
{
loop++;
TestLibrary.Logging.Write(String.Format("LOOP: {0}\n", loop));
- try
- {
- largeobj = new LargeObject();
- TestLibrary.Logging.WriteLine("Allocated LargeObject");
- }
- catch (Exception e)
+
+ if (!AllocAndCollect(loop))
{
- TestLibrary.Logging.WriteLine("Failure to allocate at loop {0}\n", loop);
- TestLibrary.Logging.WriteLine("Caught Exception: {0}", e);
return 1;
}
- largeobj = null;
+
GC.Collect();
GC.WaitForPendingFinalizers();
+ GC.Collect();
+
TestLibrary.Logging.WriteLine("LargeObject Collected\n");
}
+
TestLibrary.Logging.WriteLine("Test Passed");
GC.Collect();
+ GC.WaitForPendingFinalizers();
return ExitCode;
}
//
using System;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Collections.Generic;
}
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void FreePins()
{
foreach (GCHandle gch in list)
}
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void FreeNonPins()
{
blist.Clear();
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void FreePins2()
{
foreach (GCHandle gch in list2)
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void FreeNonPins2()
{
blist2.Clear();
using System;
+using System.Runtime.CompilerServices;
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
MakeLeak(iRep);
}
-
GC.Collect();
GC.WaitForPendingFinalizers();
return (DLinkNode.FinalCount == iRep * iObj * 20);
}
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public void SetLink(int iRep, int iObj)
{
for (int i = 0; i < iRep; i++)
}
+ [MethodImplAttribute(MethodImplOptions.NoInlining)]
public void MakeLeak(int iRep)
{
for (int i = 0; i < iRep; i++)