Skip to content

Instantly share code, notes, and snippets.

@megpay
Created February 22, 2021 22:30
Show Gist options
  • Save megpay/14681b8d953f17dfd1c1439cd4b5e2c9 to your computer and use it in GitHub Desktop.
Save megpay/14681b8d953f17dfd1c1439cd4b5e2c9 to your computer and use it in GitHub Desktop.
Manual garbage collection when RAM is limited
# Manual garbage collection due to limited RAM - useful in Kaggle competitions
import sys
for i in dir():
if sys.getsizeof(eval(i)) > 10000:
print("the size of {} is:".format(i), sys.getsizeof(eval(i))/1e+9)
import gc
del train # delete a data frame
gc.collect() # manual garbage collection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment