Fix reference counting issue for Filesystem and PathManager.