3.4. Avoid Loading Unnecessary Assemblies into Application Domains

Problem

You need to pass an object reference across multiple application domain boundaries; however, to conserve memory and avoid impacting performance, you want to ensure the CLR loads only the object's type metadata into the application domains where it is required (that is, where you will actually use the object).

Solution

Wrap the object reference in a System.Runtime.Remoting.ObjectHandle, and unwrap the object reference only when you need to access the object.

How It Works

When you pass a marshal-by-value (MBV) object across application domain boundaries, the runtime creates a new instance of that object in the destination application domain. This means the runtime must ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.