def _flushGCCache(self): app = QApplication.instance() try: app._windowCache.remove(self) except KeyError: # if self.close() is called more than once we'll end up # here. that's fine pass