Skip to content

Instantly share code, notes, and snippets.

@FrancescAlted
Created December 12, 2013 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrancescAlted/7926895 to your computer and use it in GitHub Desktop.
Save FrancescAlted/7926895 to your computer and use it in GitHub Desktop.
Why on hell Python 2.7 (and even 3.3) does not release memory as it should?
Using 2.7.6:
$ python2 ~/mem_prof.py
memory deallocated: 0.0 MB
Using 3.4b1:
$ python3 ~/mem_prof.py
memory deallocated: -1040.09765625 MB
== mem_prof.py ==
import numpy as np
from collections import deque
import gc
import time
import psutil
import os
from six.moves import range
def test():
n = 2<<25
a = np.arange(n)
d = deque()
for i in range(n):
d.append(i)
process = psutil.Process(os.getpid())
mem1 = process.get_memory_info()[0] / float(2 << 20)
del d
mem2 = process.get_memory_info()[0] / float(2 << 20)
print('memory deallocated: {} MB'.format(mem2-mem1))
x = np.arange(n)
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment