firedrakeproject/firedrake — pull request #176 by wence- (2014-02-27 14:31:17+00:00)
Title: Memory leak when creating a FunctionSpace

It seems that each time a new `FunctionSpace` is created, some memory is leaked. I've left a simple test program and the output from `valgrind` in `/scratch/ctj10/firedrake_valgrind`.

I decided to look into this after running a simulation with a relatively fine mesh and encountering the following error after a few hundred time-steps:

```
t = 119400
Adding bottom drag...
Adding momentum SU stabilisation...
Applying FreeSurfacePerturbation BC #0
Traceback (most recent call last):
File "/data/ctj10/firedrake-fluids/models/shallow_water.py", line 444, in
sw.run()
File "/data/ctj10/firedrake-fluids/models/shallow_water.py", line 384, in run
bc = DirichletBC(self.W.sub(dimension), Expression(expr.code[0]), surface_ids)
File "/data/ctj10/firedrake/python/firedrake/bcs.py", line 30, in __init__
g = Function(V).interpolate(g)
File "core_types.pyx", line 1755, in firedrake.core_types.Function.interpolate (firedrake/core_types.c:32295)
File "core_types.pyx", line 1822, in firedrake.core_types.Function._interpolate (firedrake/core_types.c:33527)
File "/usr/local/lib/python2.7/dist-packages/PyOP2-0.9.0-py2.7-linux-x86_64.egg/pyop2/backends.py", line 118, in __call__
return t(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/PyOP2-0.9.0-py2.7-linux-x86_64.egg/pyop2/caching.py", line 117, in __new__
obj = super(KernelCached, cls).__new__(cls, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/PyOP2-0.9.0-py2.7-linux-x86_64.egg/pyop2/caching.py", line 71, in __new__
obj.__init__(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/PyOP2-0.9.0-py2.7-linux-x86_64.egg/pyop2/base.py", line 2898, in __init__
self._code = preprocess(code)
File "/usr/local/lib/python2.7/dist-packages/PyOP2-0.9.0-py2.7-linux-x86_64.egg/pyop2/utils.py", line 276, in preprocess
stdout=PIPE, universal_newlines=True)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1143, in _execute_child
self.pid = os.fork()
OSError: [Errno 12] Cannot allocate memory
```
I think this was the result of a Python function which computed a diagnostic field. The function was called once per time-step and a new `FunctionSpace` object was created each time.