问题
I'm considering making limited use of C#'s dynamic
keyword. My initial time trials were astonishing - a performance hit of less than a second for 100,000 iterations (likely due to DLR caching).
I don't have access to a memory profiler, though, and Eric Lippert wrote:
Then it starts up the DLR [...] The DLR then starts up a special version of the C# compiler...
What's the memory footprint of this, and is it unloaded when the dynamic code is garbage-collected?
回答1:
is it unloaded when the dynamic code is garbage-collected?
The question presupposes an incorrect premise; the dynamically generated code isn't garbage collected in the current implementation. It is cached and the caches live until the appdomain is torn down. We don't know when the last time a particular code path is going to be called.
If you want to know the impact on virtual memory, heap memory, private bytes, shared bytes, and so on, then my suggestion is that you use a memory profiler to answer those specific questions. There are a half a dozen different "memory footprints" you could be interested in, and I don't know which one is relevant to you. Use the appropriate tool to measure whatever is interesting to you, and then you'll know.
来源:https://stackoverflow.com/questions/5212064/whats-the-memory-footprint-of-the-dlr