all groups > dotnet clr > march 2008 >
You're in the

dotnet clr

group:

DynamicMethod as an object


DynamicMethod as an object Amir Shitrit
3/3/2008 2:04:01 PM
dotnet clr:
Hi.
According to my understanding, the dynamic code generated using the
DynamicMethod class is part of the DynamicMethod instance and is subject to
garbage collection just like any other object, once no longer used.
This must mean (correct me if I'm wrong) that the dynamically generated code
is stored on the managed heap.
My question is this: if I have a DynamicMethod that calls another
DynamicMethod, how is it possible that the dynamically generated code resides
on the managed heap?
If it does, it means that its address may shift (during a GC when the heap
is compacted), which means that the second DynamicMethod that uses it may
contain a call (Opcodes.Call) to a method that no longer exists in the
specified address (after JITting, of course).

RE: DynamicMethod as an object Barry Kelly
3/7/2008 3:17:02 PM
Re: DynamicMethod as an object Barry Kelly
3/7/2008 11:25:14 PM
[quoted text, click to view]

Yes.

[quoted text, click to view]

No.

[quoted text, click to view]

The CLR takes care of the details.

(I can't reply with a longer post; something appears to be blocking my
posts...)

-- Barry

--
Re: DynamicMethod as an object Willy Denoyette [MVP]
3/8/2008 1:39:33 AM
[quoted text, click to view]



Managed code, be it dynamically generated or loaded from an assembly never
resides on the GC heap. Code is never subject to GC either, the GC only
collects object instances. The code emitted by DynamicMethod (the IL) is
stored in a special heap, managed by the class loader, the JIT keeps track
of the code and signals the CLR when it is no longer needed, in which case
the loader *may* reclaim the memory from the special heap and be reused.
Note that I said may, all depends on the current memory pressure, the CLR
will not waste it's time to release a couple of KB when there is plenty of
free memory in the special heap.

Willy.
AddThis Social Bookmark Button