`idx` calculation logic is different here and in `npy_free_cache`