You are creating 100_000 arrays, each with references to arrays of 100_000 elements. That's 10_000_000_000 elements.
$ perl -MDevel::Size=total_size -E'$x = 1.2; say total_size($x);' 24
A scalar holding a floating point number takes 24 bytes, so we're up to 240 GB without counting the arrays themselves, the references and the overheard of the memory allocation system.
In a given loop pass, you never use any index of @distance other than $distance[$u], so you don't have to keep the other elements in memory. You could dump the results to disk (or whatever it is you do with them) instead of keeping them in memory.
[ Oops, too slow. I got interrupted mid-composition. ]
In reply to Re: for-loop issue - swap gets crazy large
by ikegami
in thread for-loop issue - swap gets crazy large
by esolkc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |