Inheriting from MarshalByRefObject

You want to know when it’s appropriate to inherit from MarshalByRefObject.

Don’t inherit a new type from MarshalByRefObject or from types that derive from it. The only reason to do it is if you intend to use the type’s extra features.

It takes longer to instantiate types that derive from MarshalByRefObject. The JIT compiler can’t inline methods from these types, so method calls execute slower. A good recommendation is to split complex objects into two distinct types. Have one type expose the methods that don’t need features from MarshalByRefObject. This way, the JIT compiler can optimize calls to the object’s methods.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s