FORTH is written in postfix. You can't write 1 + 2 but 1 2 +. It is a language developed in the 1960s and still in common use, but less popular than Java.
The code quoted is for a stack, based on an array. Let us imagine your push method looks like this and you already have 99 elements and you are pushing your 100th. Count was 99, but at the point where you add the element to the array, count is 100 and count++ is the old value (99), so your 100th element goes into the array in exactly the right place. Let's imagine all goes well and you have successfully pushed the 100th element.
Now you have a count of 100, and you may wish to remove the 100th element with the pop method. If the pop method looks like this, and you take it off, then both
count and
--count are 99 in the end line of this method.
When I said "remove", that wasn't accurate. You still have 100 elements in your array, but you have no way to gain access to your 100th element (at the index 99). What will happen if you pop lots more things off the stack and don't push anything else onto it? Answer, they will remain as real references which occupy memory, and you can't get rid of them. The garbage collector won't delete them, because they are still regarded as accessible, and you can't get at them because a stack is designed not to allow access to "pop"ped elements. Now you have a memory leak. It might not appear serious if you have 100 elements, but what if those elements each occupy 3MB? The only ways to get rid of them would be to push things on top of them, which hardly helps, or set the entire stack to
null, which is probably not what you need to do.
If you try to get rid of the element from the array by setting it to
null, your pop method will look like this, remembering that
--count and
count are still equal to 99 in the "
Foo fff =" statement:
You copy the reference from the array into a local variable, which needs very little memory, then you set the original value in the array to
null. Now you have a returned value which you can use in your code, but when you have finished with it, there is no longer a reference to it in the array. So the garbage collector can easily delete it from memory, and all is well.
Have you done a search for Bloch's book?
You should be able to find a sample chapter on the net, so you can look at the chapter and try before you buy.