And an even better version of gc.collect that does it for you automatically is: https://github.com/stas00/ipyexperiments/