# Why the allocated memory keep increase in for loop

**URL:** <https://discourse.julialang.org/t/why-the-allocated-memory-keep-increase-in-for-loop/98683>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 11, 2023, 1:55pm UTC](https://discourse.julialang.org/t/why-the-allocated-memory-keep-increase-in-for-loop/98683 "2023-05-11T13:55:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![crazyfireji](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crazyfireji/32/49696_2.png) [@crazyfireji](https://discourse.julialang.org/u/crazyfireji)\
**Post date:** [May 11, 2023, 1:55pm UTC](https://discourse.julialang.org/t/why-the-allocated-memory-keep-increase-in-for-loop/98683/1 "2023-05-11T13:55:48Z")

</div>

```julia
steps = 799500:100:800000

print("样本数为：",length(steps),"\n")

function main(filepath, nx, ny, nz, steps, Axi, Axj, Ayi, Ayj)

    hx = 1.0/(nx - 1); hy = 1/(ny - 1);

    for n in steps

		print("读取$(n)步 \n")
		
        Fflow3d=FortranFile("$(filepath)OCFD$(string(n,pad=7)).dat","r")
            d, u, v, w, T = flow3D_Once(Fflow3d, nx, ny, nz)
        close(Fflow3d)

        #p = d .* T / (gamma*Ma^2)

        Tsb = 110.4 / T_inf

        Amu =@. 1.0 / Re * (1.0 + Tsb) * sqrt(T .^ 3)/ (Tsb + Tw)

        ux, uy, uz = get_grad(u, hx, hy, Axi, Axj, Ayi, Ayj, sz)
        vx, vy, vz = get_grad(v, hx, hy, Axi, Axj, Ayi, Ayj, sz)
        wx, wy, wz = get_grad(w, hx, hy, Axi, Axj, Ayi, Ayj, sz)

        Theta = ux + vy + wz

        Sigma11 = @. (ux*2 - 2/3*Theta) * Amu
        Sigma22 = @. (vy*2 - 2/3*Theta) * Amu
        Sigma33 = @. (wz*2 - 2/3*Theta) * Amu
        Sigma12 = @. (uy + vx) * Amu
        Sigma23 = @. (vz + wy) * Amu
        Sigma13 = @. (uz + wx) * Amu

        println("Write OCFD$(string(n,pad=7)).jld2")
				
        jldopen("$(filepath1)test$(string(n,pad=7))_sigma_theta.jld2","w") do f
            f["σ11"] = Sigma11
            f["σ22"] = Sigma22
            f["σ33"] = Sigma33
            f["σ12"] = Sigma12
            f["σ13"] = Sigma13
            f["σ23"] = Sigma23
            f["θ"] = Theta
        end
    end

end

@time main(filepath, nx, ny, nz, steps, Axi, Axj, Ayi, Ayj)

```

![536fec9f26a3c3c4](https://global.discourse-cdn.com/julialang/original/3X/5/5/550ac55b0f24194b30409a0364c9a9876474f109.jpeg)
