c# - Build a disposable method at runtime -
my programme creates in anytime new methods (using methodbuilder
array of byte\il) executes them 1 time , discard reference them. found don't affected gc. there way allow gc collect them or dispose them?
i found problem create new method, need load it's assembly can't unloaded after. need run methods on main appdomain. (it creates objects or modifying some) there alternative methodbuilder
, execute byte\il anyway?
use dynamicmethod
if need emit method can garbage collected later. docs:
defines , represents dynamic method can compiled, executed, , discarded. discarded methods available garbage collection.
if need build type dynamically need define dynamic assembly can collected. utilize assemblybuilder.definedynamicassembly
assemblybuilderaccess.runandcollect
option. there restrictions on can in collectible assembly detailed here.
c# reflection.emit
No comments:
Post a Comment