Sergey Kanzhelev

Hi,

Some times ago I've asked a question about memory deallocation for the old method body after SetILFunctionBody http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1110346&SiteID=1

David answered me that memory was allocated by CLR and I haven't think about it. Also he said that "This memory can be mapped directly to the module containing the function and is therefore unfreeable".

So my question is - Is there a way to understand whether the memory is unfreeable Can I save a link to that memory in order to use it in future

PS. I do understand that this memory can be read only. What if I want to save the old method body and read it again after I've replaced it by SetILCodeMap



Re: Building Development and Diagnostic Tools for .Net ICorProfiler: Can I use the memory, where the old method body was after SetILCodeMap?

David Broman - MSFT

Hi, Sergey. The memory is always unfreeable in the sense that your profiler is not allowed to free it. But at the same time you should not rely on the memory always being there for you to reference it later. For example, if the application chooses to tear down the AppDomain into which that IL was loaded, then the memory containing that IL is now invalid. In theory, there may be watchlist of events your profiler could check for to know whether the memory is still valid (e.g., AppDomains getting destroyed), but that's rather unreliable, and prone to changing in versions even if you somehow get it correct in 2.0. And I don't want to go on record listing out those events. :-)



Re: Building Development and Diagnostic Tools for .Net ICorProfiler: Can I use the memory, where the old method body was after SetILCodeMap?

Sergey Kanzhelev

Hi, David!

Thanks for your answer. It is exactly the answer I wanted to get =). Will try use it keeping in mind all the dangerous of it.