Is this a genuine memory leak?
-
BoundsChecker is reporting the following code as a memory leak: void foo() { _bstr_t bstrA; _bstr_t bstrB; bstrA = "Fred"; bstrB = "Wilma"; bstrB = bstrA.copy(); // this causes the leak // this fixes the leak - bstrB = bstrA } At first I thought it was a leak, then I decided it wasn't, now I can't decide! Is it, or isn't it :confused: Gavin
-
BoundsChecker is reporting the following code as a memory leak: void foo() { _bstr_t bstrA; _bstr_t bstrB; bstrA = "Fred"; bstrB = "Wilma"; bstrB = bstrA.copy(); // this causes the leak // this fixes the leak - bstrB = bstrA } At first I thought it was a leak, then I decided it wasn't, now I can't decide! Is it, or isn't it :confused: Gavin
Yes, that will leak. "copy" will create a copy and then the assignment will create another copy since it can not assume that the original is free for ownership. bstrB = bstrA; bstrB .Attach (bstrA .copy ()); bstrB = bstrA .copy (false); These should all work just fine. But I don't do a lot of _bstr_t work. Tim Smith "Programmers are always surrounded by complexity; we can not avoid it... If our basic tool, the language in which we design and code our programs, is also complicated, the language itself becomes part of the problem rather that part of the solution." Hoare - 1980 ACM Turing Award Lecture