Skip to content

[0.7-M3] OutOfMemoryError Loading Documents in the RichText Demo #452

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

Closed
clartaq opened this issue Mar 14, 2017 · 8 comments
Closed

[0.7-M3] OutOfMemoryError Loading Documents in the RichText Demo #452

clartaq opened this issue Mar 14, 2017 · 8 comments

Comments

@clartaq
Copy link

clartaq commented Mar 14, 2017

When loading documents in the demo, an OutOfMemoryError is thrown.

Steps to reproduce:

  1. Start the RichText demo $ gradle RichText.
  2. Click the Load Document button in the tool bar, the left-most button.
  3. Select the project license file, LICENSE, and click the "Open" button.
  4. An OutOfMemoryError is thrown and a stack trace appears in the terminal window used to launch the program.

This occurs on both Windows 10 Pro, 64-bit and Ubuntu 16.04, 64-bit.

@JordanMartinez
Copy link
Contributor

Aye, I can reproduce this. Stacktrace below:

Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space
	at java.util.ArrayList.<init>(ArrayList.java:152)
	at org.fxmisc.richtext.model.SuperCodec$1.decode(SuperCodec.java:42)
	at org.fxmisc.richtext.model.SuperCodec$1.decode(SuperCodec.java:24)
	at org.fxmisc.richtext.model.ReadOnlyStyledDocument$2.decode(ReadOnlyStyledDocument.java:121)
	at org.fxmisc.richtext.model.ReadOnlyStyledDocument$2.decode(ReadOnlyStyledDocument.java:106)
	at org.fxmisc.richtext.demo.richtext.RichText.load(RichText.java:384)
	at org.fxmisc.richtext.demo.richtext.RichText.loadDocument(RichText.java:371)
	at org.fxmisc.richtext.demo.richtext.RichText$$Lambda$280/519621340.run(Unknown Source)
	at org.fxmisc.richtext.demo.richtext.RichText.lambda$createButton$25(RichText.java:307)
	at org.fxmisc.richtext.demo.richtext.RichText$$Lambda$287/1330693596.handle(Unknown Source)
	at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
	at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
	at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
	at javafx.event.Event.fireEvent(Event.java:198)
	at javafx.scene.Node.fireEvent(Node.java:8413)
	at javafx.scene.control.Button.fire(Button.java:185)
	at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
	at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
	at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
	at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
	at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)

@JordanMartinez
Copy link
Contributor

It attempts to create an ArrayList of size: 1,382,638,440. I'm guessing the JVM args need to be adjusted here?

@TomasMikula
Copy link
Member

It appears that loading only supports files that were previously saved by the editor. What is going on here is that some bytes from the input file are interpreted as an int, the number of paragraphs, and an ArrayList is allocated for the paragraphs to be read subsequently.

@afester Do you want to comment, since you added the load/save functionality to the demo?

@JordanMartinez
Copy link
Contributor

What is going on here is that some bytes from the input file are interpreted as an int, the number of paragraphs, and an ArrayList is allocated for the paragraphs to be read subsequently.

Wow.... yeah, that would make more sense since there's definitely not that many lines in the ReadMe file.

@JordanMartinez
Copy link
Contributor

I copied the ReadMe file's contents into the demo, saved it, and then loaded that document. No issues occurred. However, the println statement I added in the SuperCoded#collectionListCodec outputted this:

Size is: 328
Size is: 1
Size is: 1
Size is: 1
{ "Size is: 1" occurs 325 times after this, for a total of 328 times }

@TomasMikula
Copy link
Member

Seems OK to me. There are 328 lines. Each line has a list (of size 1) of segments. That's a total number of 329 lists to be decoded.

@JordanMartinez
Copy link
Contributor

If we changed the file type in the save functionality and changed the load method to only look for that file type, then it would prevent this issue from arising. Additionally, adding a tooltip that explains the load button only works for previously saved documents through this demo could satisfactorily resolve this issue as it is not meant to load all kinds of documents (txt, PDF, docx, etc.), but to demonstrate a way that save/load functionality can be done.

@TomasMikula
Copy link
Member

+1 for tooltip. Also, let's emphasize that this is a demo. The format of the saved file is arbitrary and there's no guarantee a file saved with one version of the demo can be loaded with newer versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants