RFR: 8290040: Provide simplified deterministic way to manage listeners [v2]
John Hendrikx
jhendrikx at openjdk.org
Tue Oct 25 17:31:05 UTC 2022
On Thu, 1 Sep 2022 17:38:39 GMT, Nir Lisker <nlisker at openjdk.org> wrote:
>> Edit: I missed some nuance, below is the correct version.
>>
>> There are three objects involved here: the parent observable, the new observable and the conditional.
>>
>> What `when` should achieve is to make the new observable and conditional easy to garbage collect when the conditional is `false` (the parent observable is considered to be long lived so GC doesn't really apply there). The conditional and new observable refer to each other so they must have a similar life cycle.
>>
>>> What happens if they are GC'd and the conditional becomes `true` later?
>>
>> This can't happen, the conditional refers to the new observable, their life cycles are tied to each other.
>>
>> Strong references look like this when conditional is `true`:
>>
>> conditional <--> new observable <--> parent observable
>>
>> When it is `false`:
>>
>> conditional <--> new observable --> parent observable
>>
>> Conditional must have a similar life cycle as new observable if your purpose is to use `when` to break strong references to allow for GC.
>
> If I have a (dumb) method
>
>
> void someMethod(ObservableValue<String> longLivedProperty) {
> ObservableValue<Boolean> condition = new SimpleBooleanProperty(true);
> ObservableValue<String> whenProperty = longLivedProperty.when(condition)
> }
>
>
> then shouldn't `condition` and `whenProperty` be eligible for GC even when `condition` holds `true`? If not, do I not get a memory leak because I can't change `condition` to `false` to allow garbage collection?
@nlisker is this adequate, or should the docs reflect this better?
-------------
PR: https://git.openjdk.org/jfx/pull/830
More information about the openjfx-dev
mailing list