python
runtime_error
official
true
ReferenceError
ID: python/referenceerror
80%Fix Rate
95%Confidence
0Evidence
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
A weak reference proxy was used after the referent was garbage collected. The object is no longer valid.
genericOfficial Documentation
https://docs.python.org/3/library/exceptions.htmlWorkarounds
-
90% success Check if the weakref is still alive before accessing
if ref() is not None: obj = ref()
-
90% success Use weakref.WeakMethod or WeakSet for proper weak reference management
Let the framework manage lifecycle; access weakrefs through callbacks
Dead Ends
Common approaches that don't work:
-
Holding a strong reference to prevent GC
80% fail
Defeats the purpose of weak references and may cause memory leaks