NDArray: private methods to manage reference counting and invalidation