Inheriting from MarshalByRefObject

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

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

Comments
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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

w

Connecting to %s