I can't believe this exists in Swing, but I've found that when I loaded a 2MB file into JTextArea it creates literally 394,000+ java.lang.ref.Finalizer objects that hang around event after the JTextArea is released. What's worse is my memory usage spikes to 65MB! That's 30 times the size of the text string! I don't know what java.lang.ref.Finalizer object is, or why it gets created. It's a package protected object, and there is no documenation about it anywhere! I have a feeling it's wrapped up in AbstractDocument code not being very effecient in it's object allocation, but I don't know.
Here is my bug report I submitted to Sun. It's not yet approved, but since they take forever to evaluate some bug reports much less fix them. I thought I'd seek some insight into how I could make my own Document object more effecient. Does anyone have any expertise in this area to help me write a Document class to replace AbstractDocument that could fix this problem? thanks charlie ************************************************ Your report has been assigned an internal review ID of: 179612 This review ID is NOT visible on the "Java Developer Connection" (JDC). We greatly appreciate your interest in improving the quality of Java(tm) Technology from Sun Microsystems. Please be aware that the large volume of reports we receive sometimes prevents us from responding individually to each message. We currently have a three week response time for responding to Bug Reports. If the information is determined to be a new bug, or a duplicate of a known bug, you will receive a followup email containing a seven digit bug number. You may search for this bug number on the "Java Developer Connection" (JDC) at this URL: http://developer.java.sun.com/developer/bugParade/index.html. If you just reported an issue that could have a major impact on your project and you require a response, please consider purchasing one of the support offerings at this URL: http://java.sun.com/support/index.html ------------------------------------------------------ dateCreated: Fri Jan 03 16:06:03 MST 2003 type: bug cust_name: Charlie Hubbard cust_email: [EMAIL PROTECTED] jdcid: charlie76 status: Waiting category: java subcategory: classes_swing company: other release: 1.4.1 hardware: x86 OSversion: windows_2000 priority: 4 synopsis: JTextArea creates thousands of java.lang.ref.Finalizers on large text strings description: FULL PRODUCT VERSION : java version "1.4.1_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01) Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode) FULL OPERATING SYSTEM VERSION : Microsoft Windows 2000 [Version 5.00.2195] A DESCRIPTION OF THE PROBLEM : I created a small test application that reads in a file from disk and displays it in a JTextArea. When the file is around 2MB JTextArea eats up a whopping 65MB! At 3MB I got an OutOfMemoryError. I looked at what was creating so many objects in OptimizeIt, and there were over 394,000 java.lang.ref.Finalizer objects! I'm not sure what this object is because it's a package protected class that is not documented anywhere in the JDK docs, or mentioned on Sun's site. What's worse is that I don't know when they get GC'ed. In my original program where I discovered this problem these objects did not seem to get freed after the dialog was dismissed which left my program with tons of memory being used that I had no control over. When I analyzed the allocation backtraces, the hotspots were javax.swing.text.AbstractDocument.createLeafElement() which was 33.32% of allocations and javax.swing.text.GapContent.createPosition() which accounted for 66.63% of allocations. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : 1. Create a large file say around 2MBs 2. Modify the small program I included to read that file. 3. Run the program and observe the memory usage. Better run it within OptimizeIt or another memory profiling tool and see how many java.lang.ref.Finalizer objects that are created! EXPECTED VERSUS ACTUAL BEHAVIOR : Much better use of memory! This is insane how much memory is chewed up with some undocumented object. If I read in a 2MB file I hope to see memory usage change by 2-3MB not 20- 30 times that. REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- public class MemoryMonster { public static void main(String[] args) { JTextArea textAreaIps = new JTextArea( 50, 80 ); JFrame frame = new JFrame(); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setContentPane( new JScrollPane( textAreaIps ) ); frame.pack(); String strContents = ""; try { File fileHost = new File("bigfile.txt"); // change this file to point to your big file you created. int characterRead; Reader fis = new BufferedReader( new FileReader( fileHost ) ); StringWriter writer = new StringWriter( new Long( fileHost.length() ).intValue() ); while ( ( characterRead = fis.read() ) != -1 ) writer.write( characterRead ); strContents = writer.getBuffer().toString(); System.out.println("String size is " + strContents.length () ); textAreaIps.setText( strContents ); frame.setVisible( true ); } catch ( IOException e ) { JOptionPane.showMessageDialog( null, e.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE ); } } } ---------- END SOURCE ---------- CUSTOMER WORKAROUND : Doesn't seem to be one. Maybe create your own Document object that doesn't extends AbstractDocument. workaround: comments: (company - other , email - [EMAIL PROTECTED]) __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com _______________________________________________ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
