[C++-sig] Re: Memory leak when using return_internal_reference !?

David Abrahams dave at boost-consulting.com
Wed Jun 4 22:48:50 CEST 2003


gideon may <gideon at computer.org> writes:

> Hi Dave,
>
> I'm experiencing a memory leak when using the
> return_internal_reference policy.
>
> It's probably best explained using the the test_pointer_adoption_ext
> module and a
> little test program :
>
> ----------- leak.py -----------------
>
> from test_pointer_adoption_ext import *
>
> a = create("leak")
> while 1:
>     innards = a.get_inner()
>     innards = None
>     print ".",
> --------------------------------------
>
> When running this program, there is a serious memory leak. When I take out
> the line 'innards = a.get_inner()' everything is OK.
> I tried to hunt it down and it seems that life_support system created
> in life_support.cpp is never deleted, i.e. life_support_dealloc is
> never called.
>
> Do you have any idea what could be the problem ?

Perhaps... a bug in Boost.Python??!

Fixed in CVS, thanks for reporting it.  Extra bonus points if you can
supply a patch to the test that will detect this bug!

> I'm using return_internal_reference quite extensively and couldn't live
> without it :-)

Doubtless that's true.  I can't believe I never saw this one before.
That's what you get for not having tests :(
-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list