In .Net, it seems you cannot
- dynamically compile code
- call the compiled code directly (i.e. w/o "remoting", marshaling, etc) and
- remove (only) the compiled code from memory
You have to decide between 2. (by generating the code into the calling AppDomain itself) or 3. (by generating the code into a throw-away AppDomain), but you cannot have both.
Now I'm curious if this is possible in Java. I don't know enough about ClassLoaders, but it seems in Java I could
- dynamically compile code into a throw-away class loader
- call the compiled code (say, through a virtual method call to predefined interface) directly, w/o any marshaling
- remove all references to compiled class and throw-away class loader so GC will take care of removal
Is that assumption valid?