Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4037927

Graphics.setFont() causes virtual memory leaks

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Duplicate
    • Affects Version/s: 1.1
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
      None
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description



      Name: mc57594 Date: 03/10/97


      Here is code to reproduce the problem I have discovered. More
      information follows the code, so read on.

      ----- START CODE -----

      import java.lang.*;
      import java.awt.*;

      class TestFont extends Canvas
      {
        public void paint(Graphics g)
        {
          Font font;

          // Set up the new font.
          font = new Font("Helvetica", Font.PLAIN, 12);
          g.setFont(font);

          // Draw something.
          g.drawString("Font Test Program!!!", 50, 50);
        }

        // Return the preferred size for this component.
        public Dimension getPreferredSize()
        {
          return getMinimumSize();
        }

        // Return the minimum size for this component.
        public Dimension getMinimumSize()
        {
          return new Dimension(300, 100);
        }

        public static void main(String args[])
        {
          Frame f;
          TestFont tf;

          f = new Frame("Font Test Program");
          tf = new TestFont();

          f.add(tf);
          f.pack();
          f.show();

          while (true)
          {
            try {
      Thread.sleep(100);
            } catch (InterruptedException ie) {}

            tf.repaint();
          }
        }
      }

      ----- END CODE -----

      If this program is compiled under Java 1.1 (final) and run, it
      will use up virtual memory resources. To see this, I also run
      the command 'vmstat 1' in another window. It becomes obvious
      that virtual memory is definitely decreasing while the program is
      running, and that it decreases at a rate related to the frequency
      that the canvas is repainted. When virtual memory hits 0, the
      machine will crash. How badly the machine crashes depends; I've
      had machines become unusable and have to be power-cycled, or
      sometimes the windowing system just goes down, or sometimes the
      program just seg-faults and core dumps. It depends on the setup
      of the system, it seems.

      Note that if the call to Graphics.setFont() is not called, no
      leaking occurs. This indicates to me that Graphics.setFont()
      keeps around unneccessary references to the passed-in Font
      objects, but I don't have any solid idea of how it all works, of
      course. :)
      company - Caltech Seismology Lab , email - ###@###.###
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ehawkessunw Eric Hawkes (Inactive)
                Reporter:
                mchamnessunw Mark Chamness (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: