How to implement garbage collection in Numpy

I have a file with a name main.pythat refers to another file Optimisers.pythat has only functions in it and is used in a loop forin main.py. These functions have different optimization functions in them.

This one Optimisers.pythen refers to two other similar files with only functions in them that are in loops while. All of these files use numpy.

I believe this is due to loops with functions calling and creating arrays in numpy, which leads to memory overload. Therefore, I cannot finish some optimization algorithms or loop through all the possible coordinates that I would like to do.

How to ensure the removal of variables in numpy? As I understand it, numpy C libraries complicate the standard Python process. What does the team do %reset array(at the link below)? And where to implement it?

PS I read " Freeing up the huge numpy array in IPython ", and gc.collect()it doesn't work either.

+1
source share
1 answer

When the numpy array is no longer referenced, it is automatically freed by the GC. C objects are wrapped in Python objects, so it doesn't matter to you how this is implemented.

Make sure that arrays do not reference global variables, as they are closed until they are overwritten or the program exits.

, , del variablename ( , , None), - , .

, , gc.get_referrers(object).

P.S. numpy IPython, gc.collect() .

gc.disable(), gc.collect() GC .

+4

Source: https://habr.com/ru/post/1614755/


All Articles