GARBAGE COLLECTION Almost everyone knows how garbage collection can slow down a program. But there is another situation that can lead to mysterious pauses. Such slowdowns are often the result of dimensioning large arrays at the beginning of your program. Any time a new simple variable is created after the arrays are in place, there will be a pause while the computer shifts all the arrays up in memory to make space for the new variable. The effect can be seen by entering and running the following short program: 10 T=0:REM A=0:B=0:C=0:D=0:E=0 20 DIM A(7000) 30 INPUT"SIMPLE VARIABLE";A 40 T=TI:B=0:C=0:D=0:E=0 50 PRINT"SECONDS DELAY:";(TI-T)/60 60 INPUT"SIMPLE VARIABLE";A 70 T=TI:B=5:C=5:D=5:E=5 80 PRINT"SECONDS DELAY:";(TI-T)/60 For people who are unfamiliar with garbage collection, here's a brief explanation. When string variables are assigned new values (with INPUT or GET, for e xample),the old string remains in memory . Eventually, as new strings are created and old ones are superseded, BASIC runs out of free memory. At this point, the garbage collection routine takes over and shuffles memory around to get rid of the unneeded garbage strings, a process that may take several minutes. Garbage collection is an occasional problem on the 64, but not on the 128. In the example above, the delay is not due to garbage collection, but (like garbage collection) it's connected with the time it takes to move memory around There is a considerable delay while the variables in line 40 are initialize d, but there is almost no delay while th e same variables in line 70 are given ne w values. In the Commodore 64, programs are stored at the bottom of free memory Just above the program are the simple (non-array) variables. On top of them are the arrays. Every number in a num- eric array occupies five bytes, so the array in this program occupies slightly more than 35,000 bytes. Individual (simple) numeric variables need two bytes for the name and five for the value. The chunk of memory holding the large array must be moved seven bytes upward for every variable initialized in line 40. This makes a total of more than 140,000 bytes which must be moved (plus another 35,000 for the variable A used in the INPUT statement in line 30). Line 70 executed very quickly because the simple variables have been defined and no moving needs to be done. If you delete the REM in line 10, the simple variables are initialized before the array is DIMensioned, and both line 40 and line 70 will execute rapidly. You can prevent delays by predefining the variables and reserving space before the array is set up. While this program uses numeric variables and arrays to make the point, the same considerations apply to string and integer arrays. With string arrays, each array entry occupies only three bytes, so the time spent moving a string array of the same size would be slightly shorter. Simple variables can also be initialized to zero using the DIM statement, with less use of memory and less typing.