Implement memory deallocation

Add code to free structs, including ref-counted version for (potentially
shared) numeric arguments. Not absolutely essential for a program this
small but need to get into the habit of considering freeing of memory.