Hi Clemens,
Hi Roman,

    You keep creating and adding new listeners without ever removing them.
Of course this is going to leak.

What makes me wonder, I add the listeners to an Action from a newly created JTextArea. Shouldn't the action belong to the JTextArea itself and be garbage-collected too when the JTextArea is no longer reachable? (like its the case for Listeners attached to the Component directly like Mouse/Key/...-Listeners) In the case of Notepad, that would mean Swing would require the application to remove the listeners manually?
In common case you shouldn't remove listeners of course. But in your case you must remove listeners because of editor is shared between all JTextComponents (see javadoc of the JTextComponent#getActions method and BasicTextUI#getEditorKit implementation). So you added listeners not to a JTextComponent instance, but to the shared editor.

I have to admit I don't understand the concept of Actions in detail...

    It's not even related to the fact that
    the listener references the array (although that could play a role in
    more complicated leaking scenarios)

Sure, the array is just there to trigger the OOM faster ;).


Thanks, Clemens
Regards, Pavel

Reply via email to