Memory leak when iterating Point in Python
Issue #744
resolved
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)
-
-
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!
-
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. -
- marked as trivial
- edited description
- changed title to Memory leak when iterating Point in Python
- removed milestone
-
- edited description
- changed status to resolved
Fixed by e12926191335f540b8014d1a9f79fbb2547b1aa4.
- Log in to comment
Two notes to
u[0](p)
. It gives the assertion error:The mechanism used to evaluate this is
ufl_evaluate
, which is very inefficient. First methodu(p)[0]
is strongly preferred.