Completely disable IPython output caching

Viewed 2987

I'm dealing with some GB-sized numpy arrays in IPython. When I delete them, I definitely want them gone, in order to recover the memory. IPythons output cache is quite annoying there, as it keeps the objects alive even after deleting the last actively intended reference to them. I already set

c.TerminalInteractiveShell.cache_size = 0

in the IPython configuration, but this only disables caching of entries to _oh, the other variables like _, __ and so on are still created. I'm also aware of %xdel, but anyways, I'd prefer to disable it completely, as I rarely use the output history anyways, so that a plain del would work again right away.

4 Answers

Create an ipython profile:

!ipython profile create

The output might be (for ipython v4.0):

[ProfileCreate] Generating default config file: '/root/.ipython/profile_default/ipython_config.py'
[ProfileCreate] Generating default config file: '/root/.ipython/profile_default/ipython_kernel_config.py'

Then add the line 'c.InteractiveShell.cache_size = 0' to the ipython_kernel_config.py file by

!echo 'c.InteractiveShell.cache_size = 0' >> /root/.ipython/profile_default/ipython_kernel_config.py

Load another ipython kernel and check if this work

In [1]: 123
Out[1]: 123

In [2]: _1
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-51-21553803e553> in <module>()
----> 1 _1

NameError: name '_1' is not defined

In [3]: len(Out)
Out[3]: 0
Related