I discovered the same issue. I think it is a serious memory leak.
For example, if the script you are running with "run" creates large arrays or images. In a typical situation, I am running the same script over and over as I improve and test it. Because of this bug, each script run leaks whatever memory is attached to the objects created by the script. This can add up to a large amount of memory in the sort of lengthy interactive session that IPython is so good at encouraging and supporting.
I tracked it down to IPython/Magic.py:1570 (in Ipython release 0.8.4) in the magic_run function. Here is an extract:
if opts.has_key('i'):
# Run in user's interactive namespace
prog_ns = self.shell.user_ns __name__save = self.shell.user_ns['__name__'] prog_ns['__name__'] = '__main__' main_mod = FakeModule(prog_ns)
else:
# Run in a fresh, empty namespace
if opts.has_key('n'): name = os.path.splitext(os.path.basename(filename))[0]
else: name = '__main__' main_mod = FakeModule()
prog_ns = main_mod.__dict__ prog_ns['__name__'] = name
# The shell MUST hold a reference to main_mod so after %run exits,
# the python deletion mechanism doesn't zero it out (leaving
# dangling references) self.shell._user_main_modules.append(main_mod)
The last line appends the namespace of the script to a list. The list is only cleaned up if the user runs the %reset command. But that is overkill -- generally I want to keep the prompt's namespace but I am happy to overwrite the namespace when I re-run a script.
I found that commenting out the last line fixes the problem. I disagree with the comment above the last line.
I discovered the same issue. I think it is a serious memory leak.
For example, if the script you are running with "run" creates large arrays or images. In a typical situation, I am running the same script over and over as I improve and test it. Because of this bug, each script run leaks whatever memory is attached to the objects created by the script. This can add up to a large amount of memory in the sort of lengthy interactive session that IPython is so good at encouraging and supporting.
I tracked it down to IPython/ Magic.py: 1570 (in Ipython release 0.8.4) in the magic_run function. Here is an extract:
if opts.has_key('i'):
__ name__save = self.shell. user_ns[ '__name_ _']
prog_ ns['__name_ _'] = '__main__'
main_ mod = FakeModule(prog_ns)
name = os.path. splitext( os.path. basename( filename) )[0]
name = '__main__'
main_ mod = FakeModule()
prog_ ns['__name_ _'] = name
self. shell._ user_main_ modules. append( main_mod)
# Run in user's interactive namespace
prog_ns = self.shell.user_ns
else:
# Run in a fresh, empty namespace
if opts.has_key('n'):
else:
prog_ns = main_mod.__dict__
# The shell MUST hold a reference to main_mod so after %run exits,
# the python deletion mechanism doesn't zero it out (leaving
# dangling references)
The last line appends the namespace of the script to a list. The list is only cleaned up if the user runs the %reset command. But that is overkill -- generally I want to keep the prompt's namespace but I am happy to overwrite the namespace when I re-run a script.
I found that commenting out the last line fixes the problem. I disagree with the comment above the last line.