[Seaside] Component lifecycle and how to use announcement on a model

Philippe Marschall philippe.marschall at gmail.com
Mon Aug 16 17:54:40 UTC 2010

2010/8/12 Tim Mackinnon <tamackinnon at gmail.com>:
> Hi guys - as I drill through my "once simple" toy application (actually its
> not that bad - particularly compared to the java/gwt stuff I get at work) -
> I keep coming up with features that excercise new parts of seaside/pharo.
> I currently have a "model" that I store as a class variable on my root
> component. As i've split out bits of functionality from my app and moved
> them into sub-components, I've instantiated those components with that same
> shared model so they could render different parts of it. I think this is the
> right style...?
> Anyway in adding a new "Remove button" feature, it felt like it should live
> in an existing items list component - however a model update can require an
> ajax update to redraw my model state so everything looks right (and its my
> main component that coordinates this).
> So it seemed like a perfect fit for Announecments - my root could subscribe
> to a model change and then coordinate the ajax update of the correct
> components.
> I did this , and then started getting updates all over the place (even
> unexpectedly) - I'm thinking that when I subscribe to my Announcements, I
> shouldn't do this in the #initialize of my root component? I think I must
> get a new initialize every time I refresh the page - and so register another
> notification?
> So I'm wondering what the lifecycle of a WAComponent is? And where/how I
> should initialize a singleton model? I've read the bits about session's -
> but in my case I want multiple browsers to share the same model (so each
> would be in its own session - so I don't think I want to go that route?).
> Do I lazy initialize the subscription along with the singleton model (or is
> there a better way)? And when do I unsubscribe? I think I'm missing the info
> about the component lifecycle - where should I look to understand/read about
> that?

The root component usually gets garbage collected with the session.
Child components may get garbage collected earlier when they're are no
longer reachable from the root component and no longer backtracked.
The session gets garbage some time after it expires. For simplicity
and safety it's best to assume a component lives as long as the
session. If you're creating new components left and right for every
page reload then probably something went wrong.

Setting up a subscription in #initialize should be OK as long as the
model has the same lifetime as the component / session. Otherwise you
may get one of the infamous listener memory leaks.


More information about the seaside mailing list