Skip to content

Instantly share code, notes, and snippets.

@grubberr
Last active April 11, 2019 10:35
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 grubberr/99e92c3ae3f80d7b2d255b39d03e197d to your computer and use it in GitHub Desktop.
Save grubberr/99e92c3ae3f80d7b2d255b39d03e197d to your computer and use it in GitHub Desktop.
python not free memory ?
#!/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