I am working on a project where I need to dereference a module and free its memory for further model training. Here I mentioned the demo code with memory uses after certain block. I used garbage collection as well as the del function but it couldn't worked for me.
import psutil
import sys
import gc
sys.path.insert(0,'/scripts_v2')
process = psutil.Process()
mem = process.memory_info().rss/(1024**2)
print(mem)
import pandas as pd
process = psutil.Process()
mem = process.memory_info().rss/(1024**2)
print(mem)
sys.modules.pop('pandas')
#del pd
gc.collect()
process = psutil.Process()
mem = process.memory_info().rss/(1024**2)
print(mem)
I calculated the memory after a specific block of code. Here I mentioned the output of the above code.
You can see that before and after deleting the pandas library, its memory is still 60.65 MB. How can I free its memory?