Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory issue with JFileChooser #284

Closed
Abu-Abdullah opened this issue May 22, 2015 · 7 comments
Closed

memory issue with JFileChooser #284

Abu-Abdullah opened this issue May 22, 2015 · 7 comments
Assignees
Projects

Comments

@Abu-Abdullah
Copy link

Hi Mikle,

I'm opening more than 3,000 files in JFileChooser. it throwns OutOfMemoryError

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
    at java.lang.Object.clone(Native Method)
    at sun.font.StandardTextSource.<init>(StandardTextSource.java:100)
    at sun.font.TextLabelFactory.createExtended(TextLabelFactory.java:132)
    at java.awt.font.TextLine.createComponentsOnRun(TextLine.java:1030)
    at java.awt.font.TextLine.getComponents(TextLine.java:1099)
    at java.awt.font.TextMeasurer.generateComponents(TextMeasurer.java:287)
    at java.awt.font.TextMeasurer.ensureComponents(TextMeasurer.java:499)
    at java.awt.font.TextMeasurer.makeLayoutWindow(TextMeasurer.java:537)
    at java.awt.font.TextMeasurer.getLineBreakIndex(TextMeasurer.java:563)
    at java.awt.font.LineBreakMeasurer.nextOffset(LineBreakMeasurer.java:359)
    at java.awt.font.LineBreakMeasurer.nextLayout(LineBreakMeasurer.java:440)
    at javax.swing.text.TextLayoutStrategy.sync(TextLayoutStrategy.java:324)
    at javax.swing.text.TextLayoutStrategy.insertUpdate(TextLayoutStrategy.java:70)
    at javax.swing.text.FlowView.insertUpdate(FlowView.java:256)
    at javax.swing.plaf.basic.BasicTextFieldUI$I18nFieldView.insertUpdate(BasicTextFieldUI.java:400)
    at javax.swing.plaf.basic.BasicTextUI$RootView.insertUpdate(BasicTextUI.java:1610)
    at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.insertUpdate(BasicTextUI.java:1869)
    at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:201)
    at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:748)
    at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:707)
    at javax.swing.text.PlainDocument.insertString(PlainDocument.java:130)
    at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:669)
    at javax.swing.text.JTextComponent.setText(JTextComponent.java:1669)
    at com.alee.laf.filechooser.WebFileChooserPanel.updateSelectedFilesFieldImpl(WebFileChooserPanel.java:1312)
    at com.alee.laf.filechooser.WebFileChooserPanel.updateSelectedFilesField(WebFileChooserPanel.java:1278)
    at com.alee.laf.filechooser.WebFileChooserPanel$21.valueChanged(WebFileChooserPanel.java:848)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:184)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:164)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:211)
    at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:405)
    at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:415)
    at javax.swing.DefaultListSelectionModel.setSelectionInterval(DefaultListSelectionModel.java:459)

it is thrown only when selecting these files. jfilechooser will work after throwing the exception (after one minute) and all the files are selected correctly.
it might not be an issue since the number of files are big but any enhancement would be great.

@mgarin mgarin added this to the v1.30 milestone May 22, 2015
@mgarin mgarin self-assigned this May 22, 2015
@mgarin
Copy link
Owner

mgarin commented May 22, 2015

Just want to ensure - which version are you using? Because last released version (v1.28) had a few major issues with memory usage including issue with preview generation in JFileChooser which I have fixed some time ago.

You can find v1.29 pre-release artifacts here:
http://weblookandfeel.com/downloads/prerelease/
Those are much more stable and polished than the older artifacts, so I recommend using those.

I just tried opening a few folders with 10k+ image files and just wandering around file system - file chooser might take up to 100 or 200 mb of memory due to large preview image generation but that memory is almost instantly released. Selecting large amount of files doesn't seem to use a lot of memory as well.

Also, if you don't want it to waste any memory at all you can switch off image preview generation:

final WebFileChooser chooser = new WebFileChooser ();
chooser.setGenerateThumbnails ( false );

With this file chooser won't require large chunks of free memory at all.

@Abu-Abdullah
Copy link
Author

I'm using the latest one 1.29. opening the folder is fast without any issue. selecting all the files (>3000) is the issue. disable generating the thumbnails didn't help.

the program run with 512 mb, i tried it with 1gb as well. i used visualvm to track the memory and it seems there is a spike with the exception and after that it went down and everything starts to work. i will create a test case and submit it here

@mgarin
Copy link
Owner

mgarin commented May 22, 2015

Sure, looking forward to test it out :)

I tried a few more cases but still no luck - didn't find any noticeable memory spikes or exceptions.
It works just fine on < 200 mb, even if select around 5-10k files at once.

Also one thing that caught my attention - the stack trace you have provided seems to point at the text field, but it is cannot be active at the same time with multiselection. So it is pretty strange if this is exactly the exception you got when selected a lot of files.

@mgarin mgarin added bug and removed enhancement labels May 22, 2015
@mgarin mgarin modified the milestones: v1.29, v1.30 May 22, 2015
@Abu-Abdullah
Copy link
Author

this code generates the error for me:

class Test5 extends JDialog
{
   public Test5()
   {
        final WebFileChooser fc = new WebFileChooser();
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fc.setGenerateThumbnails(false);
        fc.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter("file", "bok"));
        fc.setAcceptAllFileFilterUsed(false);
        fc.setMultiSelectionEnabled(true);
        final int returnVal = fc.showOpenDialog(this);
   }

   public static void main(String args[])
   {
     WebLookAndFeel.install();
     SwingUtilities.invokeLater(new Runnable(){public void run(){new Test5();}});
   }
}

even when using -Xmx512m

@mgarin
Copy link
Owner

mgarin commented May 26, 2015

I just tried it on ~14000 images (changed "bok" to "png") with -Xmx100m and it had around 30-40 free MB of memory after selecting all the files. It is indeed not optimized for such large amount of files - probably some rendering similar to list should be used there - though I still don't see any memory leaks or issues there. Unless you are really low on memory and file chooser tries to either generte a big image preview or just select a lot of files.

Basically the selection area generates components for each selected file and this isn't too good if you have a lot of them. I will mark this issue as an enhancement and will certainly replace this component with something better.

@mgarin mgarin modified the milestones: v1.30, v1.29 May 26, 2015
@mgarin mgarin removed the bug label May 26, 2015
@mgarin
Copy link
Owner

mgarin commented Jun 9, 2015

Probably this is something OS or JDK -related. Not sure why, but it could be.
Under which OS/JDK are you trying to run that code?

@mgarin mgarin modified the milestones: v1.29, v1.3.0 May 13, 2016
@mgarin
Copy link
Owner

mgarin commented May 13, 2016

There was actually an issue with thumbnails generator - it was not releasing some of memory used for thumbnails generation and was slowly moving towards OOM exception. This have been fixed a while ago and shouldn't happen on styling branch snapshots and starting with v1.2.9 release.

@mgarin mgarin closed this as completed May 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
v1.2.9
Completed
Development

No branches or pull requests

2 participants