On Tuesday 09 August 2016 15:37, Chris Angelico wrote: [...] >> You can't be too careful with memory management. > > Right. Of course, it gets very onerous, so we tend to use a context > manager instead. > > def process(self, stuff): > with deallocate() as cleanup: > cleanup(self) > cleanup(stuff) > files = self.files > cleanup(files) > del files > files = [] > cleanup(files) > files = self.files > cleanup(files) > for file in files: > cleanup(file) > file.process(stuff) > return 1 > > There, isn't that so much better?
Ha! That's why I never use context managers -- they're too easy to write buggy code. You forgot to deallocate cleanup itself! Memory leak! -- Steve -- https://mail.python.org/mailman/listinfo/python-list