[Mono-devel-list] Problem in Marshaling Runtime Code?

Jesse Towner townerj at gmail.com
Wed Feb 23 09:11:35 EST 2005

I'm not sure if I have identified a potential problem or not, but here goes.

I was examining the code in mono/mono/metadata/marshal.c and I noticed
that there is a single method wrapper cache that is global to the entire
process. However, it is not always the case that methods are also global
to the process because sometimes they're local to the host AppDomain
that their originating assembly has been loaded into. There also appears
to be no mechanism for removing a particular wrapper from the cache, so
it is quite possible that an internal call or some runtime code could
make reference to a method that has been unloaded with its host AppDomain.

I'm also not sure how this ties in with the GC implementation, that is,
if the method wrapper cache induces a live reference to a particular
method and the parent class, which somehow might stop an AppDomain from
being unloaded. But if it doesn't cause the GC to improperly unload an
AppDomain, then their is still the issue of not recollecting dead
wrappers from the method wrapper cache. I'm not sure how XSP works, but
if it is anything like IIS, then this could be a potential memory leak.

Furthermore, since their is only a single method wrapper cache and
guarding mutex, thread contention between threads (from different
AppDomains) competing for access to the one and same cache could occur.
This problem is exacerbated when one considers that the different
threads may be trying to acquire method wrappers to methods that may be
exclusive to a particular AppDomain.

So unless I have missed something in the code, it seems this problem
could rear its ugly head at some point in the future.

If this is indeed an issue not handled elsewhere, the proposed solution
would be to encapsulate the cache and other supporting variables and
objects in a context structure per AppDomain. Then the code in marshal.c
would then be modified to use the marshaling context for the current

Jesse Towner, Lead Programmer, Hybrid Mobile Technologies, LLC
Email Addresses: <jtowner at hybrid-mobile.com>, <townerj at gmail.com>
PGP Public Key: http://www.virtuallyonline.net/personal/jesse/pgp.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20050223/cea5c87c/attachment.bin 

More information about the Mono-devel-list mailing list