You've got the right idea regarding the stack memory, although in reality it works in reverse to what you're thinking. The information is stacked on top of each other, so the oldest information is closest to the bottom. In theory (and normally in practice) when the stack gets to about 95% full, then the oldest info (the stuff on the bottom) is pulled out making room for more on top. It's been a while since I've looked at/referenced the exact numbers, but 95% of full sounds about right.
Most of the time if that message comes up, rebooting the computer then trying the code again is sufficient to clear the problem. If this is happening constantly, then you may need to parse every 250 folders (since you've determined that 250 does work).