Fixing memory leak and memory safety issues.

There was no dealloc method. Also, the accessors could be unsafe if the	containing class went away.
Also switched to immutable containers for some of the returned values.