← Back to team overview

dolfin team mailing list archive

Re: Leak in Python interface

 

On Friday 12 February 2010 16:39:59 Garth N. Wells wrote:
> Johan Hake wrote:
> > On Friday 12 February 2010 13:06:00 Garth N. Wells wrote:
> >> Garth N. Wells wrote:
> >>> I've tracked a leak in the Python interface down to the line:
> >>>
> >>>   # Initialize base class
> >>>   cpp.Form.__init__(self, self._compiled_form, self.function_spaces,
> >>> self.coefficients)
> >>>
> >>> on line 46 of form.py. If I do
> >>>
> >>>   cpp.Form.__init__(self, self._compiled_form, self.function_spaces,
> >>> [])
> >>>
> >>> then there is no observable leak. Any ideas? I checked dolfin::Form it
> >>> it looks ok. I even commented out all code in the dolfin::Form
> >>> constructor to be sure.
> >>
> >> Could the problem be in the SWIG wrapper for std::vector? The line
> >>
> >>     res = SWIG_ConvertPtrAndOwn(py_item, &itemp,
> >> $descriptor(dolfin::TYPE *), 0, &newmem);
> >>
> >> looks suspicious. Johan?
> >
> > I can have a look at it. I see that you have reported a bug.
> 
> Yes, I dug deep enough that I could identify the problem precisely
> enough for a bug report, but I couldn't fix it.

That's cool! 

It might be that we increase the refcount of the passed python object (Form in 
this case), and then we do not decrease it when the call is finished. You can 
check this by calling 

  sys.getrefcount(object)

and check if this changes after the call.

I also wonder if this happens for similar objects when a share_ptr is _not_ 
used to store the C++ object.

Johan


> Garth
> 
> > Johan
> >
> >> Garth
> >>
> >>> Below is the script that I've been testing with.
> >>>
> >>> Garth
> >>>
> >>>
> >>> from dolfin import *
> >>> parameters["form_compiler"]["cpp_optimize"] = True
> >>> parameters["form_compiler"]["optimize"] = True
> >>> mesh = UnitSquare(16, 16)
> >>> for t in xrange(20000):
> >>>     for level in xrange(100):
> >>>         V  = FunctionSpace(mesh, "CG", 1)
> >>>         v  = TestFunction(V)
> >>>         u  = Function(V)
> >>>         u0 = Function(V)
> >>>         L = v*(u-u0)*dx
> >>>         b = assemble(L)
> >>>     print "----"
> >>>
> >>>
> >>>
> >>> _______________________________________________
> >>> Mailing list: https://launchpad.net/~dolfin
> >>> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> >>> Unsubscribe : https://launchpad.net/~dolfin
> >>> More help   : https://help.launchpad.net/ListHelp
> >>
> >> _______________________________________________
> >> Mailing list: https://launchpad.net/~dolfin
> >> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> >> Unsubscribe : https://launchpad.net/~dolfin
> >> More help   : https://help.launchpad.net/ListHelp
> 



References