Article ID: 236332 - Last Review: June 18, 2001 - Revision: 1.0 PRB: Memory Leak and Array Parameters Are Cleared When Method Object in MTS Doesn't Work
This article was previously published under Q236332 On This PageSYMPTOMS
If an object's method receives an array as a parameter and the object is configured to run in MTS, then the argument is cleared out if the object returns with an error. This only happens under the following circumstances:
CAUSE
The cause is a bug in the stub provided by MTS.
RESOLUTIONWorkaroundThe simplest workaround is to use late binding; that is to declare the object As Object instead of the specific class type. To do this in Visual Basic, change the Dim statement for your object variable on which the method is executed. Instead of:use this: Note that this method avoids both the argument cleaning and the memory leak. Note to Visual C++ clients: You have to make your call through IDispatch to use this workaround. This includes packing the method parameters in a DISPPARAMS structure and providing for all the required information in the GetIdsOfNames and Invoke calls. Please review the Platform SDK for more information on this. If this is not a valid workaround in your scenario another solution is to pass as an argument a copy of the array, not the real array itself. To accomplish this, make a copy of the array and use that as the call argument. If an error occurs, only the copy is destroyed and you still have the original data. However, in this case the memory leak still occurs. NOTE: For Visual C++ clients, you need to copy SafeArray, not just alias a pointer to it. To do this use the SafeArrayCopy function in the Oleauto.h file. If no error occurred in the method call and if you expect the server to modify the contents of this array, then copy back the contents of the argument array to the original variable and continue working as usual. If an error did occurred, use the original array in your error handling (the copy is cleared). STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. MORE INFORMATIONSteps to Reproduce Behavior
When you run this code, notice that the array content is preserved. If you look at the private byte count for the package MTX.exe instance using the Windows NT Performance Monitor notice that in this case there is no leak either. REFERENCESFor additional information and a partial fix, click the article number below
to view the article in the Microsoft Knowledge Base:
244795
(http://support.microsoft.com/kb/244795/EN-US/
)
FIX: Memory Leak in MTS when COM Exception Raised
| Other Resources Other Support Sites
CommunityArticle Translations |






Windows Live
Facebook
Twitter
Linkedin
Digg it
Yahoo
Delicious
StumbleUpon
Yammer
Reddit
Technorati
FriendFeed
Email

Back to the top