crusaderky
crusaderky

Reputation: 2692

Debug CPython memory fragmentation

I have a long-running CPython 3.8 process. After a while, it's using a huge amount of RAM. I have tried

  1. running gc.collect()
  2. using pympler to discover all known Python objects
import gc
import psutil
from pympler import muppy, summarize

gc.collect()
total_ram = psutil.Process().memory_info().rss
all_objects = muppy.get_objects(include_frames=True)
s = summary.summarize(all_objects)
python_objects_size = sum(row[2] for row in s)

Output: 102 MiB Python objects, 824 MiB RSS memory!

[EDIT] 3. using tracemalloc; which also returns ~100MiB worth of python objects

[EDIT 2] export PYTHONMALLOC=malloc does not solve the problem.

Is there a way to query the CPython memory manager to figure out

Related

Upvotes: 7

Views: 732

Answers (1)

Charles
Charles

Reputation: 127

Maybe try a different memory debugger. It is possible to use valgrind with python.

Upvotes: 0

Related Questions