Improving object cleanup/manual destruction of objects.
The API's memory leaks have been plugged. Some of these fixes carry over
to the GUI version. next commit should be porting the rest over.
Cleanup of the API and InstancesBuilder code. No need to explicitly call
the cleaner methods, they'll run automatically once they're able to.