Question and Answer Database FAQ2790C.txt StringToOleStr () is causing a huge memory leak Category :ActiveX Platform :Win95/NT Product : Applies to all Question: My code looks as follows: ... String str; int i = 0; while (i < 100){ str = "Pass #" + String(i); BSTR bsStr = StringToOleStr (str); ... } ... This loop causes a HUGE memory leak. I tryed deleting the BSTR but that did not help any. When I comment out the line BSTR bsStr = StringToOleStr (str); the memory leak goes away, so I know that it has something to do with the BSTR, but I don't know what. Answer: Well, you are right that the problem is that you are not freeing the memory allocated by the call to StringToOleStr. But the problem is that BSTR's use system memory so delete will not free them up. You need to use the API call SystemFreeString (BSTR bstr) to free up the memory. 8/4/98 9:19:26 AM
Last Modified: 01-SEP-99