On Thu, 27 Sep 2012 11:28:17 +0200
Martijn Dashorst <martijn.dasho...@gmail.com> wrote:

> I encounter the following code quite often in our company's codebase:
> 
> @Override
> protected void onBeforeRender() {
>     add(AttributeModifier.replace("class", someCondition ? "someValue"
> : "someOtherValue"));
> }
> 
> This is of course a (often a minor) memory leak: each time the
> component gets rendered, a new attribute modifier is added to the list
> of behaviors, each overwriting the class attribute. The correct code
> would of course be:

This is simply a bug, in my opinion, and there's an easy fix that you
have already shown.

Changing AttributeModifier to become temporary would be a silent
behavior change that will very likely bite many more users than those
who have code with the shown bug. I haven't seen this in our codebase
at all, for example. But I'd certainly scratching my head if these
modifiers suddenly were to disappear after the first request.

So, my opinion is: -1. Better to improve documentation for this.

Carl-Eric

Reply via email to