%matplotlib inline import gc import matplotlib.pyplot as plt len(gc.get_objects()) plt.hist([1,2]) len(gc.get_objects()) gc.collect()