How can I explicitly free memory in Python?

According to Python Official Documentation, you can explicitly invoke the Garbage Collector to release unreferenced memory with gc.collect(). Example:

import gc


You should do that after marking what you want to discard using del:

del my_array
del my_object

Leave a Comment