python
resource_error
ai_generated
partial
MemoryError
ID: python/memoryerror
55%Fix Rate
78%Confidence
95Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 311 | active | — | — | — |
Root Cause
Process exceeded available RAM. Common with large datasets, recursive structures, or memory leaks.
genericWorkarounds
-
82% success Process data in chunks/batches instead of loading all into memory
for chunk in pd.read_csv(path, chunksize=10000):
Sources: https://docs.python.org/3/library/functions.html#iter
-
78% success Use memory-mapped files or streaming approaches (mmap, generators)
import mmap; with open('large.bin','rb') as f: mm = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
Dead Ends
Common approaches that don't work:
-
Increase swap space
80% fail
Swap is orders of magnitude slower, making the program unusable
-
Upgrade to more RAM
60% fail
Often the data processing approach itself is inefficient
Error Chain
Leads to:
Preceded by:
Frequently confused with: