Solve a system of linear equations many times without allocating memory

That said, I still think that worrying about allocations is not something one should consider unless they are willing to pay quite a bit in code complexity for very marginal improvements. Here is a function for those who want to experiment:

using LinearAlgebra, BenchmarkTools

function f(n, m)
    A = rand(n, n)
    b = rand(n)
    z = 0.0
    for _ in 1:m
        z += (A \ b)[1]
        A .+= 1
        b .+= 1
    end
    z
end

@benchmark f(20, 20) # try n = 10, 20, 30, 50

where the outer loop was included to make profiling easier. Around 1–2% of the time is spent on GC even for small matrices. LAPACK time dominates everything. This becomes much more prominent for larger matrices.