31. Memory Profiling
Profiling memory usage helps detect leaks and optimize usage.
Example with memory_profiler
pip install memory-profiler
from memory_profiler import profile
@profile
def create_list():
return [i for i in range(10**6)]
Run with:
python -m memory_profiler script.py
Wrap-Up
Memory profiling reveals inefficient memory use in code.