Skip to content

Possible memory leak? #5047

Closed
Closed
@timholy

Description

I seem to have obtained possible evidence of a memory leak. I'm relying on results reported by our diagnostic tools, and of course one caveat is the question of whether the tool is correct.

Here's the test script:

using Grid
A = rand(1000,1000)
x = rand(2:999, 10^6, 2) + rand(10^6, 2) - 0.5
Ai = InterpGrid(A, BCnil, InterpLinear)

function testgrid(Ai, x)
    y = zero(eltype(Ai))
    for i = 1:size(x,1)
        y += Ai[x[i,1],x[i,2]]
    end
    y
end

testgrid(Ai, x[1:5,:])
@time testgrid(Ai, x)

Grid has always been written with the intention of being allocation-free (during interpolation; there is allocation during initialization), but until @loladiro's tuple work returning multiple arguments from functions like interp_coords_1d led to "unnecessary" allocations. I think #4042 changed that; certainly, it led to a 2x speedup in the performance of this test code.

However, I'm still puzzled by the result of the output of @time:

julia> include("testgrid.jl")
elapsed time: 0.35688972 seconds (48006676 bytes allocated)
500208.87506182125

There's a pretty huge amount of memory allocated here, suggesting that it gets allocated on each iteration. Yet the profiler suggests there are no calls to jl_gc_collect. My concern is that the observed speedup is largely due to the absence of gc runs which, from the standpoint of memory consumption, should have been happening.

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorperformanceMust go faster

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions