Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8194833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:56:58+00:00 2026-06-07T04:56:58+00:00

I’m using Swing and I have a JFrame containing a few JPanels, and inside

  • 0

I’m using Swing and I have a JFrame containing a few JPanels, and inside one of them there is a JTextArea.

The JTextArea content is set when an user clicks on a certain menu (ActionListener.actionPerformed(populate())).

The content is taken from a 30MB text file:

private void populate () {
        StringBuilder strB = new StringBuilder();
        try {
            FileReader fr = new FileReader("file30mb.txt");
            BufferedReader br = new BufferedReader(fr);
            String strLine;

            while ((strLine = br.readLine()) != null) {
                strB.append(strLine).append(System.getProperty("line.separator"));
            }

            fr.close();
            br.close();
        } catch (IOException e) {
            System.err.println(e);
        }

        jTextArea1.setEditable(false);
        jTextArea1.setText(strB.toString());
        jTextArea1.setCaretPosition(0);
}

This process takes a lot of memory usage, about 200MB.

There is another menu and when an user clicks on it the JTextArea is cleared (basically it calls a method that does jTextArea1.setText(null)). The event is handled the same way of before: ActionListener.actionPerformed(free()).

So when the JTextArea is empty I expect that the memory usage is lower than before… But unfortunately it’s not true. If I go in the task manager I see the same memory usage of before (about 200MB), but the JTextArea is empty!

What am I missing?

EDIT I also tried this:

jTextArea1.setText(strB.toString());
jTextArea1.setText("");
Runtime r = Runtime.getRuntime();
r.gc();
System.out.println(jTextArea1.getDocument().getLength()); // prints "0"

But it still takes 200MB of memory.

EDIT 2 If I remove the “GUI part” (I mean jTextArea1.setText() etc.) it still takes a lot of memory. It should take “0 memory” because I don’t write anything in the JTextArea, but I just read a text file and then do nothing. Am I wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:57:02+00:00Added an answer on June 7, 2026 at 4:57 am

    Few reasons:

    • garbage collection runs periodically, it won’t free memory immediately

    • JVM process memory and heap memory usage are two distinct things. Enable verbose GC logging or connect to your application using jconsole/jvisualvm and check real heap usage. Run GC manually

    • Is Ctrl + Z still working, allowing you to restore previous (30 MB) contents? You get the idea…

    If none of these are right, use memory profiler like Eclipse MAT to find out what holds a reference to this huge object (you’ll find char[] of 60 MB size).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.