Google Groups Home
Help | Sign in
OutOfMemoryException but I don't know why
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Jason Cavett  
View profile
 More options May 16, 2:53 pm
Newsgroups: comp.lang.java.programmer
From: Jason Cavett <jason.cav...@gmail.com>
Date: Fri, 16 May 2008 11:53:52 -0700 (PDT)
Local: Fri, May 16 2008 2:53 pm
Subject: OutOfMemoryException but I don't know why
I am currently writing a portion of an application that is used to
edit and display formulas to the user.  The users add the formula
tokens through a point and click interface and the tokens are added as
JLabels to the panel.  By existing as JLabels, the users can select
the labels and make modifications to them given the controls
available.

The issue I am having is that, if a user starts to copy and paste the
JLabels, an OutOfMemoryException quickly occurs.  I ran some memory
profiling (via TPTP) and the JLabels are taking up quite a bit of
memory, but not nearly enough to cause an OOMEx.  I tested this theory
by creating a test program to head into an infinite loop and create a
ton of JLabels and it was up to >30,000 before it decided to hit a
OOMEx.  The number of JLabels being copied and pasted are < 1,000.
Nothing else in the application was taking up any significant amount
of memory.  I have allocated 512MB to the JVM.

Is there anything that is apparently wrong with this code (this is
where the JLabels are added)?  I am really stuck.  It's not a memory
leak (based on my research with TPTP) and I'm not creating *THAT* many
JLabels.  Any suggestions?

(For the record, "this" class refers to a class that extends JPanel.)

    private void setTokens(List<String> tokens) {
        List<JLabel> components = new ArrayList<JLabel>();

        // convert the tokens to JLabels which will be added to the
panel
        for (String tokenString : tokens) {
            JLabel tokenLabel = new JLabel(" " + tokenString + " ");
            tokenLabel.setSize(tokenLabel.getPreferredSize());
            tokenLabel.setOpaque(false);
            tokenLabel.addMouseListener(tokenSelection);
            tokenLabel.addMouseListener(panelFocusSetter);
            components.add(tokenLabel);
        }

        // get the panel's size
        Dimension panelSize = this.calculatePanelSize(components);
        this.setPreferredSize(panelSize);
        this.setSize(panelSize);

        // now populate the panel
        // populating with line wrapping turned on requires that the
size of the
        // panel is taken into consideration
        this.removeAll();
        for (JLabel label : components) {
            this.add(label);
        }
    }

Thanks


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google