Can I manage the memory by myself?

zhijie_sun
Sat, 08 Apr 2023 14:38:37 +0000
General Usage

I have a code, the GC live and RSS memory increased quickly when running, while I don’t need such big memory to do basic computation. I need to allocate lots of small dict for intermidiate computing before, and the memory increase quickly; to avoid memory allocation, I pre-allocate two array to avoid repeatly allocate small dict, it put off the invreasing. But still get lots of allocation when I repeatly add some sparse array to get final one.
I am tired of avoiding allocation, and I guess memory issues I encountered is cause from GC’s lazy? (I allreadly used GC.gc() through the cycle)
So I wonder if I can pre-define some memory for long-time variables (maybe existed throughout the code, while generated gradually as the program running), and other memory for intermediate calculation, I can clear all the memory in it when I finished one cycle.
Help, thanks in advance!

17 posts - 8 participants