Fixing a memory leak in a BizTalk component -XLangMessage and XLangPart

Posted: May 27, 2010  |  Categories: BizTalk Uncategorized

In my last blog entry i described how i found a memory leak in a BizTalk component. This entry will describe what the problem was and how I fixed it.

The memory analysis pointed to a class library that was not releasing memory. Inside the class library there was a method , shown below, that was being used to add an email attachment to a message.

public static void AddMessagePart(XLANGMessage msg, object oPart, string sPartName)
{
    msg.AddPart(oPart, sPartName);
    XLANGPart part = msg[sPartName];
    part.SetPartProperty(typeof(MIME.FileName), sPartName + “.xml”);
}

This method is called by reference from an orchestration. What is wrong with it?

The XLANGMessage and XLANGPart parameters do not adhere to the rules for managing memory correctly (see http://support.microsoft.com/kb/917841). The following lines must be added to the method to cleanup;

if (msg != null)
{
    msg.Dispose();
}
if (part != null)
{
    part.Dispose();
}

Thanks to Greg Forsythe for pointing this problem out.

BizTalk360
BizTalk Server

Over 650+ customers across
30+ countries depend on BizTalk360

Learn More
Serverless360
Azure

Operate efficiently with enterprise-grade Azure monitoring,
tracing, remediation & governance in one platform

Learn More

Back to Top