Slicing an array in Julia creates a copy, which is where your allocations are coming from. You can do @view(b[1:n, 1:n])
to create a view instead, which will avoid the unnecessary copy. See Could you explain what are views? - #3 by stevengj for some more explanation.