← Back to team overview

dolfin team mailing list archive

Re: Leak in Python interface

 

On Saturday 13 February 2010 01:50:42 Garth N. Wells wrote:
> Johan Hake wrote:
> > Thanks for the precise bug report!
> >
> > While i forgot to update instant, hiding the real leak
> 
> This is the third I've found in the past week (Instant, FFC and this
> one), and having multiple leaks makes each one hard to find!

True...
 
> > a while I finally
> > nailed it. We needed to delete a void pointer to a shared_ptr<Foo*>. I do
> > not think SWIG allocated any extra memory, we just forgot to reduce a ref
> > count on a shared_ptr.
> 
> Very nice - looks great now. No memory increase for the simple loop
> script that I've been testing with.
> 
> Are there any pro/cons in terms of the wrapper code to using
> dolfin::Array versus std::vector for passing pointers between Python and
> C++?

I do not think there are any particular pros, as we either way need to fetch 
the underlaying C++ pointer from the passed Python list. It is this procedure 
that is difficult in this case. Filling a std::vector or an dolfin::Array, 
once we have the pointers aren't that difficult. So I would say that this 
question could be addressed as a pure C++ decision.

The point with dolfin::Array is when contiguous arrays can be sent back and 
forth between Python and C++.

Speaking of Arrays, I have added some more thoughts about this at the 
Blueprint. If we want to close this Blueprint before DOLFIN 0.9.7 we need to 
address the last issues. 

Johan
 
> Garth
> 
> > Johan
> >
> > 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.
> >>
> >> 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