FEniCS wrapper or PyCall for Julia uses too much memory



Happy Monday Everyone,
I was trying to use the julia package “FEniCS” for making a Navier Strokes Simulation, but as time goes higher so does memory. Here is the for loop that I got and modified from tutorial 8 of the FEniCS package.

for n =0:(num_steps-1)
    # Update current time
    global t += dt
    # Step 1: Tentative velocity step
    b1 = assemble(L1)
    [apply(bc,b1) for bc in bcu]
    solve(A1, vector(u_), b1, "gmres","amg")#, "bicgstab", "hypre_amg"
    b2 = assemble(L2)
    [apply(bc,b2) for bc in bcp]
    solve(A2, vector(p_), b2, "gmres","amg")#,  "bicgstab", "hypre_amg")

    b3 = assemble(L3)
    solve(A3, vector(u_), b3, "gmres","amg")#,  "bicgstab", "hypre_amg")
    if n%savestep==(savestep-1)
        write(xdmffile_u,u_, t)
        write(xdmffile_p,p_, t)
        # Save nodal values to file
        #store(timeseries_u,vector(u_), t)
        #store(timeseries_p,vector(p_), t)
    global p_n = FeFunction(Q)
    global u_n = FeFunction(V)
    global p_ = FeFunction(Q)
    global u_ = FeFunction(V)

the FeFunction part was my attempt to lower the memory as I believe the assign function is not freeing up memory after assigning. I am not sure if it is because of PyCall or the FEniCS package that uses PyCall. I read that since julia does not have a clear function for variables to clear up memory I can assign a value to it to clear up memory so I assigned a function to it. Despite my attempt the memory problem did not resolve and somewhere in that for loop I am building up memory. Python fenics simulations by others use with the same resolution 0.1% memory while my julia fenics simulation uses 40% (more than 60 Gb). Alternative finite element packages i looked at in julia dont seem to have methods to program navier strokes (just poisson and heat diffussion) nor to have a periodic function space. How should I tackle this problem?