I wrote a Python program that acts on a large input file to create a few million objects representing triangles. The algorithm is:
(del
can be your friend, as it marks objects as being deletable when there no other references to them. Now, often the CPython interpreter keeps this memory for later use, so your operating system might not see the "freed" memory.)
Maybe you would not run into any memory problem in the first place by using a more compact structure for your data.
Thus, lists of numbers are much less memory-efficient than the format used by the standard array
module or the third-party numpy
module. You would save memory by putting your vertices in a NumPy 3xN array and your triangles in an N-element array.