ManagedPtr implementation (ForeignPtr-like typeclass)