<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
    <title></title>
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Hi Clemens,
    <blockquote
cite="mid:CAFvQSYRCsVDEtTOz2Cscx3s01DSgScgL1Gwhrw3AePWc3S9XNA@mail.gmail.com"
      type="cite">
      <meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
      Hi Roman,<br>
      <br>
      <div>
        <blockquote>You keep creating and adding new listeners without
          ever removing them.<br>
          Of course this is going to leak. </blockquote>
        <div><br>
          What makes me wonder, I add the listeners to an Action from a
          newly created JTextArea.<br>
          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)<br>
          In the case of Notepad, that would mean Swing would require
          the application to remove the listeners manually?<br>
        </div>
      </div>
    </blockquote>
    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.<br>
    <blockquote
cite="mid:CAFvQSYRCsVDEtTOz2Cscx3s01DSgScgL1Gwhrw3AePWc3S9XNA@mail.gmail.com"
      type="cite">
      <div>
        <div><br>
          I have to admit I don't understand the concept of Actions in
          detail...<br>
          <br>
          Â </div>
        <blockquote>
          It's not even related to the fact that<br>
          the listener references the array (although that could play a
          role in<br>
          more complicated leaking scenarios) <br>
        </blockquote>
        <div> </div>
        <div>Sure, the array is just there to trigger the OOM faster ;).
          <br>
          <br>
          <br>
          Thanks, Clemens<br>
        </div>
      </div>
    </blockquote>
    Regards, Pavel<br>
  </body>
</html>