[C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE

Matthew B. Keyes Keyes at simcrest.com
Fri Oct 14 00:17:52 CEST 2005


Sorry guys, it was late when I posted this, so the typo:

return object(new CreateClassA());

Meant to be:

return object(new A());

I was under the impression that the object class functioned as a
reference counting auto_ptr of sorts... That solves that one for me.

I'll post more later on the string issue 'cause I'm out of time right
now.  Thanks for the help!

"Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com> wrote in message
news:<20051013155914.43599.qmail at web31505.mail.mud.yahoo.com>...
> --- mjkeyes at sbcglobal.net wrote:
> 
> > Hey again, I'm back.
> 
> Hi Arnold! :)
> 
> > Here is some pseudo-code of what I'm doing:
> 
> Could you please turn this into a self-contained reproducer? Please
explain
> exactly how you compile and link. Note that you have to be very
careful to not
> mix debug and release builds under Windows.
> 
> > class A
> > {
> > public:
> >   void SetString(const std::string &sVal)
> >   {
> >     m_sString = sVal; <--- Memory leak
> 
> I am doing things like this all the time and I am sure it doesn't leak
for me.
> 
> >   }
> > 
> >   void DoStuff()
> >   {
> >     SetString(msc_sString);
> >   }
> > protected:
> >   static const std::string msc_sString;
> > }
> 
> Probably a side issue: do you really want "static" here?
> 
> > 
> > class B
> > {
> > public:
> >   object CreateClassA()
> >   {
> >     return object(new CreateClassA()); <---- memory leak
> 
> What is this? Does this even compile?
> In any event, of course you get a memory leak if you use new like
that.
> Ideally, you don't have any "unencapsulated" new in your code. Always
use
> boost::shared_ptr<T>(new T) or std::auto_ptr<>(new T) or any other
smart
> pointer.
> 
> > Any suggestions?  I'm not getting any errors from the interpreter.
> 
> We need a complete reproducer.
> 
> Cheers,
>         Ralf
> 
> 
> 
> 		
> __________________________________ 
> Yahoo! Music Unlimited 
> Access over 1 million songs. Try it free.
> http://music.yahoo.com/unlimited/



More information about the Cplusplus-sig mailing list