linux-packaging-mono/mono/tests/dynamic-method-churn.cs
Xamarin Public Jenkins (auto-signing) 0abdbe5a7d Imported Upstream version 5.18.0.142
Former-commit-id: 7467d4b717762eeaf652d77f1486dd11ffb1ff1f
2018-10-09 08:20:59 +00:00

31 lines
571 B
C#

using System;
using System.Reflection;
using System.Reflection.Emit;
class Program
{
//See GH #9176
static int Main (string[] args) {
for (int i = 0; i < 20000; ++i) {
DynamicMethod dm = new DynamicMethod(
$"dm_{i}",
null,
new Type[0],
typeof(Program).Module);
ILGenerator il = dm.GetILGenerator();
il.Emit(OpCodes.Ret);
Action a = (Action) dm.CreateDelegate(typeof(Action));
a();
var m = a.Method;
m.Invoke (null, null);
if ((i % 50) == 0) {
GC.Collect ();
GC.WaitForPendingFinalizers ();
}
}
return 0;
}
}