Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / March 2008

Tip: Looking for answers? Try searching our database.

DynamicMethod as an object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Amir Shitrit - 03 Mar 2008 22:04 GMT
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).

Thanks.
Barry Kelly - 07 Mar 2008 23:17 GMT
Barry Kelly - 07 Mar 2008 23:25 GMT
> the dynamic code generated using the
> DynamicMethod class [...] is subject to
> garbage collection

Yes.

> dynamically generated code
> is stored on the managed heap.

No.

> 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).

The CLR takes care of the details.

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

-- Barry

Signature

http://barrkel.blogspot.com/

Willy Denoyette [MVP] - 08 Mar 2008 00:39 GMT
> Hi.
> According to my understanding, the dynamic code generated using the
[quoted text clipped - 14 lines]
>
> Thanks.

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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.