Is this leaking?
- Posted by Falkon 1313 <Falkon1313 at AOL.COM> Nov 28, 1999
- 453 views
The following loop is giving me trouble and I can't understand it. -------- r = {} for c = 1 to length( s ) do r = r & n1 & n2 end for -------- n1 and n2 are integers. With s being a length 1,017 sequence, it works just fine. If s is a length 115,444 sequence, it locks up, as if it were in an infinite loop, though it obviously isn't. (It might eventually do something, but I waited about 10 minutes, and it's never taken more than a few minutes to get an 'out of memory' error from infinite recursion.) In Windows98, I can kill it with Ctrl+Break, but before long I get fatal errors and 'System Dangerously Low on Resources', so it's using up a lot of RAM and not releasing it when broken out of. In DOS I have to reboot. I have 64MB of RAM. Counting sequence overhead, the final version of r should only be (230,888 * 4 + 24) = 923,576 bytes. At most, while processing the last byte, the expression would only be: 923,568 = 923,568 & 4 & 4 for 1,847,144 bytes, and I'd think it'd be more like 923,568 = 8 & 4 & 4 = for 923,584bytes. Unless I'm counting wrong. Either way, that shouldn't cause a lockup. Even if I didn't have enough RAM, it should give an Out of Memory error instead of appearing to go into an infinite loop. My best guess is that maybe it's not releasing the memory used by the temporary sequences formed by the concatenation until after it exits the loop, and somehow that's causing an 'under-the-hood' infinite loop. Either of the following, OTOH, work just fine, even with the large image it's finished before I can blink, no lockups or windows errors. --------- r = {} for c = 1 to length( s ) do r2 = r2 & { n1, n2 } end for --------- r = {} for c = 1 to length( s ) do r2 = r2 & ( n1 & n2 ) end for --------- All three forms are logically equivalent if not procedurally the same. So what's the difference? The temporary memory used by literal sequences, atom & atom concatenations, or sequence & sequence concatenations is released or reused for each iteration, while that used by sequence & atom concatenation isn't? Why no out-of-memory crash?