In my understanding, JIT-ed code never gets released from memory while the program is running. Does this mean that repeatedly calling .Compile()
on expression trees leaks memory?
The implication of that would be to only compile expression trees in static constructors or cache them in some other way, which may not be as simple. Right?
When you want to have a richer interaction, you need to use Expression Trees. Expression Trees represent code as a structure that you can examine, modify, or execute. These tools give you the power to manipulate code during run time. You can write code that examines running algorithms, or injects new capabilities.
Expression trees that represent lambda expressions are of type LambdaExpression or Expression<TDelegate>. To execute these expression trees, call the Compile method to create an executable delegate, and then invoke the delegate.
An expression tree is a representation of expressions arranged in a tree-like data structure. In other words, it is a tree with leaves as operands of the expression and nodes contain the operators. Similar to other data structures, data interaction is also possible in an expression tree.
They are probably GCed... LambdaExpression.Compile()
uses the LambdaCompiler.Compile(LambdaExpression, DebugInfoGenerator)
class, that through one of the LambdaCompiler
constructors uses DynamicMethod
that, from MSDN:
Defines and represents a dynamic method that can be compiled, executed, and discarded. Discarded methods are available for garbage collection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With