← Back to team overview

dolfin team mailing list archive

Re: [Bug 521507] Re: Memory leak in Python Expression interface

 

On Sunday 14 February 2010 11:27:11 Garth Wells wrote:
> Looks like it is a SWIG bug, which can be worked around by removing the
> SWIG flag '-dirvtable', see the change

Ok, this actually make sense, as the -dirvtable creates a lookup table for 
faster dynamic dispatches during runtime. This table is probably not deleted. 
It is created the fist time a director method is called, and explains why the 
code did not leak when the call to eval was out commented, as it was never 
created. It also explains why the code did not leak when the expression were 
created only once.

I can try to see if I can produce a minimal example that I can attach to a bug 
report upstream to SWIG.

Johan
 
> http://bazaar.launchpad.net/~dolfin-core/dolfin/main/revision/4511
> 
> ** Changed in: dolfin
>    Importance: Undecided => High
> 
> ** Changed in: dolfin
>     Milestone: None => 0.9.7
>

-- 
Memory leak in Python Expression interface
https://bugs.launchpad.net/bugs/521507
You received this bug notification because you are a member of DOLFIN
Team, which is subscribed to DOLFIN.

Status in DOLFIN: Fix Committed

Bug description:
The below code leads to a memory leak (I see a leak over about 2MB over 90s). The leak is related to the Expression. If I comment out the call to

    eval(Array<double>&, const Array<double>&);

from 

  dolfin::GenericFunction::evaluate(double*, const double*, const ufc::cell) const

I don't detect a leak.

------

from dolfin import *
parameters["form_compiler"]["cpp_optimize"] = True
parameters["form_compiler"]["optimize"] = True

class MyExpression(Expression):
    def eval(self, values, x):
        if x[0] < DOLFIN_EPS:
            values[0] =  1.0

mesh = UnitSquare(32, 32)
for t in xrange(20000):
    for level in xrange(100):
        V  = FunctionSpace(mesh, "CG", 1)
        v  = TestFunction(V)
        u  = Function(V)
        u0 = Function(V)
        f  = MyExpression(degree=1)
        L = v*(u-u0)*dx + v*f*ds
        b = assemble(L)
    print "----"





References