G
Guest
I have an unmanaged COM DLL written in VC++ 6.0. Its threading model is
registered as "Both" and it has a free thread marshaller. I am using the
object from an ASPX page. On the creation of the first instance of the
object, aspnet_wp.exe's memory use goes way up (20M+), then stays pretty
stable. In each execution of the page, I create a new instance of the object
and then free the object using
While System.Runtime.InteropServices.Marshal.ReleaseComObject(theObj) > 0
End While
However, I do notice that the amount of memory in use does increase over
that base amount by a few K on each request. It seems that it increases by an
amount that is related to the size of some string results returned from the
object (some of the "Get" methods of the object return String (BSTR)
results). I am using the following code inside the DLL to set the values of
those results (some details excluded for brevity):
STDMETHODIMP CTheObj::get_Buffer(long BuffNum, BSTR *Buff) {
// stringBuffer is a char[] member variable whose value is set by other
methods
*Buff = ConvertStringToBSTR((const char *)stringBuffer);
return S_OK;
} // end of get_Buffer
// Not my code, copied from other fora
inline BSTR ConvertStringToBSTR(const char* pSrc) {
if(!pSrc) return NULL;
DWORD cwch;
BSTR wsOut(NULL);
if (cwch = ::MultiByteToWideChar(CP_ACP, 0, pSrc, -1, NULL, 0)) {
// get size minus NULL terminator
cwch--;
wsOut = ::SysAllocStringLen(NULL, cwch);
if (wsOut) {
if(!::MultiByteToWideChar(CP_ACP, 0, pSrc, -1, wsOut, cwch)) {
if (ERROR_INSUFFICIENT_BUFFER == ::GetLastError())
return wsOut;
::SysFreeString(wsOut);//must clean up
wsOut = NULL;
} // end if
} // end if
} // end if
return wsOut;
}; // end of ConvertStringToBSTR
In the ASPX page, I set the String variable to Nothing after I use it.
Am I doing something incorrectly here?
registered as "Both" and it has a free thread marshaller. I am using the
object from an ASPX page. On the creation of the first instance of the
object, aspnet_wp.exe's memory use goes way up (20M+), then stays pretty
stable. In each execution of the page, I create a new instance of the object
and then free the object using
While System.Runtime.InteropServices.Marshal.ReleaseComObject(theObj) > 0
End While
However, I do notice that the amount of memory in use does increase over
that base amount by a few K on each request. It seems that it increases by an
amount that is related to the size of some string results returned from the
object (some of the "Get" methods of the object return String (BSTR)
results). I am using the following code inside the DLL to set the values of
those results (some details excluded for brevity):
STDMETHODIMP CTheObj::get_Buffer(long BuffNum, BSTR *Buff) {
// stringBuffer is a char[] member variable whose value is set by other
methods
*Buff = ConvertStringToBSTR((const char *)stringBuffer);
return S_OK;
} // end of get_Buffer
// Not my code, copied from other fora
inline BSTR ConvertStringToBSTR(const char* pSrc) {
if(!pSrc) return NULL;
DWORD cwch;
BSTR wsOut(NULL);
if (cwch = ::MultiByteToWideChar(CP_ACP, 0, pSrc, -1, NULL, 0)) {
// get size minus NULL terminator
cwch--;
wsOut = ::SysAllocStringLen(NULL, cwch);
if (wsOut) {
if(!::MultiByteToWideChar(CP_ACP, 0, pSrc, -1, wsOut, cwch)) {
if (ERROR_INSUFFICIENT_BUFFER == ::GetLastError())
return wsOut;
::SysFreeString(wsOut);//must clean up
wsOut = NULL;
} // end if
} // end if
} // end if
return wsOut;
}; // end of ConvertStringToBSTR
In the ASPX page, I set the String variable to Nothing after I use it.
Am I doing something incorrectly here?