"yaksa" warning related to the VectorFunctionSpace

Dear community,

I noticed that the Function substantiated from VectorFunctionSpace will induce [WARNING] yaksa: 2 leaked handle pool objects. Similar issues also appear in dolfinx.fem.petsc.create_vector if the form contains that Function.

I found a similar post in Problem solving in parallel slower than in serial - General - FEniCS Project, but I still did not figure out how to fix it elegantly. Here is the MWE (based on 0.6.0 version).

import dolfinx
from mpi4py import MPI
import ufl

domain = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 8, 8,
                                         dolfinx.mesh.CellType.quadrilateral)
V = dolfinx.fem.VectorFunctionSpace(domain, ("CG", 1))
S = dolfinx.fem.FunctionSpace(domain, ("CG", 1))

u_v = dolfinx.fem.Function(V)
u_s = dolfinx.fem.Function(S)
u_v.vector  # Invoke the warning
u_s.vector  # No warning

w = ufl.TestFunction(V)
form = dolfinx.fem.form(ufl.dot(u_v, w) * ufl.dx)
dolfinx.fem.petsc.create_vector(form)  # Invoke the warning

See Possible memory leak in `dolfinx.fem.Function.vector`? · Issue #2559 · FEniCS/dolfinx · GitHub

2 Likes

Thanks, @francesco-ballarin !

I put the updated code here for future readers:

import dolfinx
from mpi4py import MPI
import ufl

domain = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 8, 8,
                                         dolfinx.mesh.CellType.quadrilateral)
V = dolfinx.fem.VectorFunctionSpace(domain, ("CG", 1))
S = dolfinx.fem.FunctionSpace(domain, ("CG", 1))

u_v = dolfinx.fem.Function(V)
u_s = dolfinx.fem.Function(S)
u_v.vector  # Invoke the warning
u_s.vector  # No warning
u_v.vector.destroy()  # Need to add this line

w = ufl.TestFunction(V)
form = dolfinx.fem.form(ufl.dot(u_v, w) * ufl.dx)
vec = dolfinx.fem.petsc.create_vector(form)  # Invoke the warning
vec.destroy()  # Need to add this line
1 Like