Last active
April 11, 2019 10:35
-
-
Save grubberr/99e92c3ae3f80d7b2d255b39d03e197d to your computer and use it in GitHub Desktop.
python not free memory ?
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
#!/usr/bin/python3 | |
import os | |
import uuid | |
import psutil | |
RELEASE_MEMORY = True | |
def get_rss_memory(): | |
p = psutil.Process(pid=os.getpid()) | |
with p.oneshot(): | |
return p.memory_full_info().rss / 1024 / 1024 | |
l1 = [] | |
for _ in range(1000000): | |
record = { | |
'key1': str(uuid.uuid4()), | |
'key2': str(uuid.uuid4()), | |
'key3': str(uuid.uuid4()), | |
'key4': str(uuid.uuid4()), | |
'key5': str(uuid.uuid4()), | |
} | |
l1.append(record) | |
print("%d Mb" % get_rss_memory()) | |
l2 = [] | |
for record in l1: | |
new_record = {} | |
if RELEASE_MEMORY: | |
new_record['key1'] = (record['key1'] + '.')[:-1] | |
else: | |
new_record['key1'] = record['key1'] | |
l2.append(new_record) | |
print("%d Mb" % get_rss_memory()) | |
l1 = l2 | |
if RELEASE_MEMORY: | |
print("%d Mb <- all ok, it has to be about 350Mb ???" % get_rss_memory()) | |
else: | |
print("%d Mb <- what is hell here it has to be about 350Mb ???" % get_rss_memory()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment