Memory leak when iterating Point in Python

Issue #744 resolved
Steven Vandekerckhove created an issue
from dolfin import *
import numpy as np

mesh = UnitSquareMesh(4, 4)

U = VectorFunctionSpace(mesh, "CG", 1)
u = Function(U)

p = (0.1, 0.1)

print u(p)[0] # Works
print u[0](p) # Works

p = Point(np.array((0.1, 0.1)))

print u(p)[0] # Works
print u[0](p) # Leaks

Comments (5)

  1. Jan Blechta

    Two notes to u[0](p). It gives the assertion error:

    *** Error:   Unable to complete call to function operator[]().
    *** Reason:  Assertion i < 3 failed.
    *** Where:   This error was encountered inside ../../../../../dolfin/geometry/Point.h (line 100).
    

    The mechanism used to evaluate this is ufl_evaluate, which is very inefficient. First method u(p)[0] is strongly preferred.

  2. Steven Vandekerckhove reporter

    Strange, I don't get this error in my docker container, just a memory leak... Good to know u(p)[0] is preferred.

    Thanks for your comment!

  3. Jan Blechta

    The reason is that Point does not follow correctly Python iterable protocol.

    from dolfin import *
    def foo(): pass
    foo(*Point())
    

    *Point() starts unpacking the point until iteration ends. But it either never ends or fails on assertion.

  4. Log in to comment