On Thu, 13 Oct 2022 22:06:15 GMT, Andy Goryachev <ango...@openjdk.org> wrote:

>> Since this was quite wordy, and since pictures are worth a thousand words...
>> 
>> Here is the situation when you have a Label with its Skin:
>> 
>> ![image](https://user-images.githubusercontent.com/995917/195709660-0bdad680-9240-48e9-9f8e-ae4b40ab7047.png)
>> 
>> When that Skin is replaced, dispose is called which toggles `active` to 
>> `false`.  Furthermore, the Label will no longer reference the Skin.  This 
>> image then shows the state of the references, and which objects can be GC'd:
>> 
>> ![image](https://user-images.githubusercontent.com/995917/195710017-413af0ec-1c0f-4329-adb5-d5c3072c0008.png)
>
> Thank you for explanations, @hjohn .
> 
> This *might* work for Skins, of course, though it is not exactly what is 
> needed for Skins (I will explain why in 
> https://github.com/openjdk/jfx/pull/908 because of context).
> 
> In the context of this PR, I can see how a memory leak can be created when a 
> developer has the `active` property as long lived and that would prevent the 
> whole chain from being collected.  An example would be trying to attach to 
> the Window.showingProperty(), adding listeners that reference Nodes that are 
> supposed to be GC'd when removed from the said window (dynamically creating 
> detail panes as response to selection event, for example).
> 
> I think what you propose here is good, but, as any other place where 
> listeners are added, must be used with caution (may be reflect that fact in 
> javadoc?)

And, more specifically, is there a way to break the strong reference between 
the `active` property and the dependent fluent chain?

-------------

PR: https://git.openjdk.org/jfx/pull/830

Reply via email to