Re: Does This Leak Memory?
From: Larry Brasfield (donotspam_larry_brasfield_at_hotmail.com)
Date: 10/19/04
- Next message: Lawrence Groves: "Re: Does This Leak Memory?"
- Previous message: Carl Daniel [VC++ MVP]: "Re: Does This Leak Memory?"
- In reply to: Lawrence Groves: "Does This Leak Memory?"
- Next in thread: Lawrence Groves: "Re: Does This Leak Memory?"
- Reply: Lawrence Groves: "Re: Does This Leak Memory?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 19 Oct 2004 08:48:47 -0700
"Lawrence Groves" <lgroves@ducost.deleteme.com> wrote in message news:OnPJC9etEHA.3564@tk2msftngp13.phx.gbl...
> Hi all,
Hi.
> A coleague of mine told me something strange about some code of mine that has run for years (not necessarily without error). I
> pass a string to an ADO connection object's open method, who's prototype is:
>
> inline HRESULT Connection15::Open ( _bstr_t ConnectionString, _bstr_t UserID, _bstr_t Password, long Options )
>
> I call the routine like so:
>
> _bstr_t bsConn = "whatever";
>
> cpConn->Open(bsConn, _bstr_t("user"), _bstr_t("pass"), -1);
>
> but he says I should do the following to avoid a memory leak:
>
> _bstr_t bsConn = "whatever";
>
> _bstr_t bsUser("user");
> _bstr_t bsPass("pass");
>
> cpConn->Open(bsConn, bsUser, bsPass, -1);
>
> He claims that the two temporaries in the first case may leak memory.
That would depend on the compiler. A defective
one *might* leak memory by mishandling temporary
objects. To my knowledge, MSVC++ does not
suffer that particular defect. Nor have I heard of
other C++ compilers with such a defect. Can your
colleague name a C++ compiler that does?
> Something to do with the underlying BSTR not being cleaned up properly because of the way the class's copy constructor works.
I would be quite surprised to find that such a basic
bug would survive until the Nth generation of the
library defining _bstr_t. In fact, I would bet real
money against such a proposition.
> Am I loosing it? It seems to me that the first piece of code would't leak, but I would like a second opinion.
Unlikely. But why do you wonder? Have you not
yet tested your code for leaks? Perhaps you should
explore why so many people do that and how easy
it is. Then do it.
> TIA, Loz.
You're welcome.
-- --Larry Brasfield email: donotspam_larry_brasfield@hotmail.com Above views may belong only to me.
- Next message: Lawrence Groves: "Re: Does This Leak Memory?"
- Previous message: Carl Daniel [VC++ MVP]: "Re: Does This Leak Memory?"
- In reply to: Lawrence Groves: "Does This Leak Memory?"
- Next in thread: Lawrence Groves: "Re: Does This Leak Memory?"
- Reply: Lawrence Groves: "Re: Does This Leak Memory?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|