Memory leak in time-dependant dynamic mesh

Hi, I want to implement adaptive mesh refinement for time-dependant problem. I need to create new mesh, fes and GridFunction in the time-loop.
But, it will cause memory leak. Following is a small test code:

from ngsolve import *
# import gc
# gc.enable()

def Setup():
    mesh = Mesh(unit_square.GenerateMesh(maxh=1))
    for i in range(8):
        mesh.Refine()

    fes = H1(mesh, order=1, autoupdate=True)
    phi_old = GridFunction(fes, autoupdate=True)

    phi_old.Set(k) # <-- turn on this line will cause memory leak

    del phi_old
    # gc.collect()

    print("mesh number = {} ".format(mesh.ne))

for k in range(1000):
    Setup()
    print("k = {} ".format(k))

As the iterations progress, even though the number of mesh elements used each time remains consistent, the memory usage of the program continues to increase. del phi_old dosen’t work.

I found a similar post in this forum, but it also cause memory leak.

Attachment:

memory_leak.py (468 Bytes)

thank you for the report, it’s fixed now in the development version,
Joachim