You've definitely found something -- running
valgrind on awk with your example and again on GNU awk (from
MacPorts) shows that sure enough awk leaks memory like a sieve, while GNU awk doesn't.
It might be worth
filing a Bug Report with Apple (not that you'll ever hear back but it might at least call their attention to it and get it fixed in a future release).
Consider installing GNU awk, which is not only not afflicted by this apparent bug, but also more powerful. As a quick fix, if you don't want to install GNU awk right now, you can modify your code as shown below, and even the Apple-provided awk doesn't leak memory with this. There's one major caveat --
you're not guaranteed to have your array items in any particular order, so it may not be suitable for what you want to accomplish:
Code:
# Store the first 800 words
NR < 801 { word[NR] = $1 }
# Now access a stored array value without a memory leak
NR > 800 {
for (i in word)
printf("%d\t%d\t%s\n", NR, i, word[i]);
}