@@ -31,10 +31,13 @@ public void AddsSigned()
3131 _ = LLVM . InitializeNativeAsmParser ( ) ;
3232 _ = LLVM . InitializeNativeAsmPrinter ( ) ;
3333
34- var engine = module . CreateMCJITCompiler ( ) ;
34+ using var engine = module . CreateMCJITCompiler ( ) ;
3535 var func = engine . GetPointerToGlobal < Int32Int32Int32Delegate > ( def ) ;
3636 var result = op1 + op2 ;
3737 Assert . That ( func ( op1 , op2 ) , Is . EqualTo ( result ) ) ;
38+
39+ engine . FreeMachineCodeForFunction ( def ) ;
40+ _ = engine . RemoveModule ( module ) ;
3841 }
3942
4043 [ Test ]
@@ -56,10 +59,13 @@ public void ShiftsRight([Range(0, 256)] int op1, [Range(0, 8)] int op2)
5659 _ = LLVM . InitializeNativeAsmParser ( ) ;
5760 _ = LLVM . InitializeNativeAsmPrinter ( ) ;
5861
59- var engine = module . CreateMCJITCompiler ( ) ;
62+ using var engine = module . CreateMCJITCompiler ( ) ;
6063 var func = engine . GetPointerToGlobal < Int32Int32Int32Delegate > ( def ) ;
6164 var result = op1 >> op2 ;
6265 Assert . That ( func ( op1 , op2 ) , Is . EqualTo ( result ) ) ;
66+
67+ engine . FreeMachineCodeForFunction ( def ) ;
68+ _ = engine . RemoveModule ( module ) ;
6369 }
6470
6571 [ Test ]
@@ -81,10 +87,13 @@ public void ComparesGreaterThan([Range(0, 10)] int op1, [Range(0, 10)] int op2)
8187 _ = LLVM . InitializeNativeAsmParser ( ) ;
8288 _ = LLVM . InitializeNativeAsmPrinter ( ) ;
8389
84- var engine = module . CreateMCJITCompiler ( ) ;
90+ using var engine = module . CreateMCJITCompiler ( ) ;
8591 var func = engine . GetPointerToGlobal < Int32Int32Int8Delegate > ( def ) ;
8692 var result = op1 > op2 ? 1 : 0 ;
8793 Assert . That ( func ( op1 , op2 ) , Is . EqualTo ( result ) ) ;
94+
95+ engine . FreeMachineCodeForFunction ( def ) ;
96+ _ = engine . RemoveModule ( module ) ;
8897 }
8998
9099 [ Test ]
@@ -112,10 +121,14 @@ public void CallsFunction([Range(0, 10)] int op1, [Range(0, 10)] int op2)
112121 _ = LLVM . InitializeNativeAsmParser ( ) ;
113122 _ = LLVM . InitializeNativeAsmPrinter ( ) ;
114123
115- var engine = module . CreateMCJITCompiler ( ) ;
124+ using var engine = module . CreateMCJITCompiler ( ) ;
116125 var func = engine . GetPointerToGlobal < Int32Int32Int32Delegate > ( entryDef ) ;
117126 var result = op1 + op2 ;
118127 Assert . That ( func ( op1 , op2 ) , Is . EqualTo ( result ) ) ;
128+
129+ engine . FreeMachineCodeForFunction ( entryDef ) ;
130+ engine . FreeMachineCodeForFunction ( addDef ) ;
131+ _ = engine . RemoveModule ( module ) ;
119132 }
120133
121134 [ Test ]
@@ -136,9 +149,12 @@ public void ReturnsConstant([Range(0, 10)] int input)
136149 _ = LLVM . InitializeNativeAsmParser ( ) ;
137150 _ = LLVM . InitializeNativeAsmPrinter ( ) ;
138151
139- var engine = module . CreateMCJITCompiler ( ) ;
152+ using var engine = module . CreateMCJITCompiler ( ) ;
140153 var func = engine . GetPointerToGlobal < Int32Delegate > ( def ) ;
141154 Assert . That ( func ( ) , Is . EqualTo ( input ) ) ;
155+
156+ engine . FreeMachineCodeForFunction ( def ) ;
157+ _ = engine . RemoveModule ( module ) ;
142158 }
143159
144160 [ Test ]
@@ -160,8 +176,11 @@ public void ReturnsSizeOf()
160176 _ = LLVM . InitializeNativeAsmParser ( ) ;
161177 _ = LLVM . InitializeNativeAsmPrinter ( ) ;
162178
163- var engine = module . CreateMCJITCompiler ( ) ;
179+ using var engine = module . CreateMCJITCompiler ( ) ;
164180 var func = engine . GetPointerToGlobal < Int32Delegate > ( def ) ;
165181 Assert . That ( func ( ) , Is . EqualTo ( 8 ) ) ;
182+
183+ engine . FreeMachineCodeForFunction ( def ) ;
184+ _ = engine . RemoveModule ( module ) ;
166185 }
167186}
0 commit comments