Multiple memory related changes.

1. Turn `Handle` instances into weak references, meaning that their
   existance is tracked by `CountedObject` instances.
2. Add `Memory` utility class which contains memory related utility
   functions.
3. Add custom vector class, and convert everything to use that instead
   of `std::vector`.