Skip to content

Commit

Permalink
On removal of site, clear bases of its site manager.
Browse files Browse the repository at this point in the history
This fixes a reference leak from a parent site manager.
See `issue 1 <https://github.com/zopefoundation/zope.site/issues/1>`.
  • Loading branch information
Michael Howitz committed Sep 10, 2020
1 parent 7a0414c commit b31d288
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ CHANGES
3.10.0 (unreleased)
-------------------

- Nothing changed yet.
- On removal of a site, clear the bases of its site manager. This fixes a reference leak
from a parent site manager. See
`issue 1 <https://github.com/zopefoundation/zope.site/issues/1>`_.


3.9.2 (2010-09-25)
Expand Down
5 changes: 4 additions & 1 deletion src/zope/site/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,14 @@ def SiteManagerAdapter(ob):

def changeSiteConfigurationAfterMove(site, event):
"""After a site is moved, its site manager links have to be updated."""
local_sm = site.getSiteManager()
if event.newParent is not None:
next = _findNextSiteManager(site)
if next is None:
next = zope.component.getGlobalSiteManager()
site.getSiteManager().__bases__ = (next, )
local_sm.__bases__ = (next, )
else:
local_sm.__bases__ = ()


@zope.component.adapter(
Expand Down
13 changes: 12 additions & 1 deletion src/zope/site/site.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ site hierarchy is as follows:

_____ global site _____
/ \
myfolder1 myfolder2
myfolder myfolder2
|
myfolder11

Expand Down Expand Up @@ -352,3 +352,14 @@ sitemanager's bases should be set to global site manager.
>>> nosm['root'] = myfolder11
>>> myfolder11.getSiteManager().__bases__ == (gsm, )
True

Deleting a site unregisters its site manger from its parent site manager:

>>> del myfolder2['myfolder21']
>>> myfolder2.getSiteManager().subs
()

The removed site manager now has no bases:

>>> myfolder21.getSiteManager().__bases__
()

0 comments on commit b31d288

Please sign in to comment.