replace ObjectContext pointers with shared_ptr

The ObjectContext pointers are shared using a ref data member that needs to be updated by the caller. This is tedious and error prone. In this patch series, all pointers are replaced with shared_ptr for automatic reference counting and the ref data member is removed. They are stored in a SharedPtrRegistry instance to automatically keep track of the instances in use.