java.lang.OutOfMemoryError: Java heap space

Status
Not open for further replies.

jBellavance

New member
Hi,

I downloaded TeensyduinoInstall.exe and installed it on Arduino 1.8.3, with Windows 10 (24GB)
I have a Teensy LC on port : 14(teeensy)

I Wrote this sketch:
Code:
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.println(F("Hello, World!"));
}
It ran fine, for about 20 seconds. Then the Serial monitor stopped printing. About 10 seconds later, I got those messages.
Code:
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
	at java.io.BufferedInputStream.<init>(BufferedInputStream.java:203)
	at java.io.BufferedInputStream.<init>(BufferedInputStream.java:183)
	at sun.util.locale.provider.RuleBasedBreakIterator$1.run(RuleBasedBreakIterator.java:448)
	at sun.util.locale.provider.RuleBasedBreakIterator$1.run(RuleBasedBreakIterator.java:445)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.util.locale.provider.RuleBasedBreakIterator.readFile(RuleBasedBreakIterator.java:444)
	at sun.util.locale.provider.RuleBasedBreakIterator.readTables(RuleBasedBreakIterator.java:375)
	at sun.util.locale.provider.RuleBasedBreakIterator.<init>(RuleBasedBreakIterator.java:321)
	at sun.util.locale.provider.BreakIteratorProviderImpl.getBreakInstance(BreakIteratorProviderImpl.java:169)
	at sun.util.locale.provider.BreakIteratorProviderImpl.getLineInstance(BreakIteratorProviderImpl.java:106)
	at java.text.BreakIterator.createBreakInstance(BreakIterator.java:571)
	at java.text.BreakIterator.createBreakInstance(BreakIterator.java:553)
	at java.text.BreakIterator.getBreakInstance(BreakIterator.java:544)
	at java.text.BreakIterator.getLineInstance(BreakIterator.java:483)
	at javax.swing.text.TextLayoutStrategy.sync(TextLayoutStrategy.java:300)
	at javax.swing.text.TextLayoutStrategy.insertUpdate(TextLayoutStrategy.java:70)
	at javax.swing.text.FlowView.loadChildren(FlowView.java:143)
	at javax.swing.text.CompositeView.setParent(CompositeView.java:139)
	at javax.swing.text.FlowView.setParent(FlowView.java:289)
	at javax.swing.plaf.basic.BasicTextAreaUI$PlainParagraph.setParent(BasicTextAreaUI.java:239)
	at javax.swing.text.CompositeView.replace(CompositeView.java:217)
	at javax.swing.text.BoxView.replace(BoxView.java:181)
	at javax.swing.text.CompositeView.loadChildren(CompositeView.java:114)
	at javax.swing.text.CompositeView.setParent(CompositeView.java:139)
	at javax.swing.plaf.basic.BasicTextUI$RootView.setView(BasicTextUI.java:1328)
	at javax.swing.plaf.basic.BasicTextUI.setView(BasicTextUI.java:693)
	at javax.swing.plaf.basic.BasicTextUI.modelChanged(BasicTextUI.java:682)
	at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.insertUpdate(BasicTextUI.java:1862)
	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)

Have I forgot to do something?

Thanks for your help.

Jacques
 
That loop() will run so fast and print so much as to overwhelm the receiving machine. Put a delay(100); in that to start and to see the difference.
 
Thanks, It seems to run ok now.

With this simple Hello World sketch, the IDE reports 6968 byte of program space and 2104 bytes of dynamic memory used. Is this normal?
 
Last edited:
Yes, that is normal. The ARM processors have USB hardware on chip - but PJRC USB interface software is included to make that work when USB Serial is selected. Select USB NONE and recompile a simple sketch and you'll get a better idea of the Code and RAM space that occupies. Perhaps a blink example without Serial.print - as that also brings in a base set of code to support it.

That USB support takes some space not used on other systems where the USB support is a stand alone chip - but provides true robust onboard USB support to present as multiple USB types. The Teensy core software and overhead is really small - just enough to enable and power up the ARM chip. Adding any interface after that adds code in proportion to the complexity to implement it.
 
Something to keep in mind for sure. There are a few other things that may help someday if you get that tight on code or RAM space. But generally the Teensy is uploaded with only required code to make the processor run, adding on code only when used. With minimal support for some Arduino standards.

I just did a small sample to see how small it gets - and it results in a failure on T_3.1 after upload - so I'm going to go enter a thread for that.
// USB type : No USB
// ------------------------------
// Smallest Code - PJRC Yield - T_3.1 :: Uploads and Blinks
// Sketch uses 3488 bytes (1%)
// Global variables use 900 bytes (1%)

// Smallest Code - void Yield - T_3.1 :: Upload and Blink fails
// Sketch uses 2280 bytes (0%)
// Global variables use 488 bytes (0%)
 
I'm running it now on my Windows 10 test machine. It's been going for several minutes, still hasn't managed to overwhelm Java and give that error.

Windows Task Manager is showing about 544 Mbyte used by Java. Any chance you can give this another try (printing without delays) and watch Java's memory usage on your machine?

capture.jpg
 
Status
Not open for further replies.
Back
Top