Article ID: 917841 - View products that this article applies to.
Consider the following scenario. In Microsoft BizTalk Server 2006, you pass an XLANG message or an XLANG message part to a method call as a parameter. In this scenario, a reference leak may occur. This article describes how to avoid a reference leak.
To avoid a reference leak when you pass an XLANG message or an XLANG message part to a method call as a parameter, use the following methods.
Method 1: Pass a message or a message partWhen you pass a message part, do not pass the message part as an XLANGPart argument or return a value of type XLANGPart. This can cause reference leaks that are difficult to resolve. Instead, pass the message part as the type of the part. Consider the following code examples.
Code example 1
Code example 2
When you pass a message, do not put an XLANGPart member in a collection that has a lifetime that is longer than the lifetime of the function call. Instead, pass the message itself as an XLANGMessage object. Then, use the XLANGMessage subscript operators to access the message part inside the function call. Consider the following code example.
Method 2: Pass an XLANGMessage object and an XLANGPart objectDo not use an XLANGMessage object or an XLANGPart object as an orchestration parameter. Instead, use a message type parameter to pass a message. If you want to pass a message part, pass the message. Then, use the part in the function, the subroutine, or the program that is called. If you want only the part value in the function, the subroutine, or the program that is called, use the part type to pass the message.
Method 3: Pass a message to user codeTo avoid reference leaks, do not return an XLANGMessage parameter for a method call. If you return an XLANGMessage parameter that is passed in, you cannot call the Dispose method on the parameter inside the method call. If you do this, lifetimes are violated and an exception error occurs.
When you pass a message through an XLANGMessage parameter to user code, the message is referenced to the root context. Typically, messages are not referenced to the root context. The lifetime of the root context is the lifetime of the orchestration instance. The root context is used to make sure that the user code does not hold the message after the orchestration instance finishes and closes.
If you have to release a message reference in a loop when the message has been passed through an XLANGMessage argument, you can use the XLANGMessage.Dispose method. You can use the XLANGMessage.Dispose method to release the reference to the root context if the following conditions are true:
However, you can use a Dispose method for the class to clean up a collection of XLANGMessage messages. Consider the following code example.
Article ID: 917841 - Last Review: June 12, 2007 - Revision: 1.2
Contact us for more help
Connect with Answer Desk for expert help.