Created
December 12, 2013 11:53
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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