############################################################################## # # Copyright (c) 2003 Zope Corporation and Contributors. All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE # ############################################################################## """LeakBGone An experimental monkey-patch product that tries to ensure that no unexpected objects (especially acquisition-wrapped objects) remain on the REQUEST object that could cause a circular reference (and thus a memory leak). It is still bad form to store such objects in a request, whether this hack works or not ;) """ from ZPublisher.HTTPRequest import HTTPRequest from zLOG import LOG, INFO def close(self): """Replace the standard REQUEST.close method with one that explicitly wipes out everything and takes no prisoners.""" # If this works ok, next step is to add some logging whenever # we find a wrapped object, so that we can stub out the cause. names = self.__dict__.keys() for name in names: value = getattr(self, name) clear = getattr(value, 'clear', None) if clear is not None and callable(clear): clear() setattr(self, name, None) value = None def initialize(context): HTTPRequest.close = close LOG('LeakBGone', INFO, 'LeakBGone initialized')