# Out of memory problem

**URL:** <https://discourse.processing.org/t/out-of-memory-problem/1300>\
**Category:** Coding Questions\
**Created:** [June 27, 2018, 2:33am UTC](https://discourse.processing.org/t/out-of-memory-problem/1300 "2018-06-27T02:33:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mmminh](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Mmminh](https://discourse.processing.org/u/Mmminh)\
**Post date:** [June 27, 2018, 2:33am UTC](https://discourse.processing.org/t/out-of-memory-problem/1300/1 "2018-06-27T02:33:11Z")

</div>

when I run the program for 20 minute it will get slower and then stop and say it out of memory

I think problem is at code below

> if (port.available()\>0){  
> String val=port.readString();  
> String list=split(val,‘,’);  
> pressglobe= int(list[0]);  
> lowlim1globe=int(list[1]);  
> uplim1globe=int(list[2]);
> 
> press2globe=int(list[3]);  
> lowlim2globe=int(list[4]);  
> uplim2globe=int(list[5]);
> 
> press3globe=int(list[6]);  
> lowlim3globe=int(list[7]);  
> uplim3globe=int(list[8]);

the Arduino just sent the data from serial port to this program as 10,20,10 something like this  
any body have an idea please help  
_btw this is all of my code_

> // Need G4P library  
> import g4p\_controls._;  
> import processing.serial._;  
> import meter.\*;  
> Serial port;  
> Meter m1,m2,m3;  
> public String txt=“”;  
> public String txt2=“”;  
> public String txt3=“”;  
> public int pressglobe=0;  
> public int lowlim1globe=0;  
> public int uplim1globe=0;
> 
> public int press2globe=0;  
> public int lowlim2globe=0;  
> public int uplim2globe=0;
> 
> public int press3globe=0;  
> public int lowlim3globe=0;  
> public int uplim3globe=0;
> 
> public int MODEglobal=0;  
> public int MODE2global=0;  
> public int MODE3global=0;
> 
> int screen =0;  
> GButton screenbutton;  
> GTextArea txa;  
> public void setup(){  
> frameRate(60);
> 
> port = new Serial(this,“/dev/cu.wchusbserial1420”,9600);  
> size(900, 950, JAVA2D);  
> background(254,254,254);  
> customGUI();
> 
> m1=new Meter(this, 230,50);  
> m1.setTitle(“Pressure(kPa)1”);  
> String scaleLabels1={“-50”,“-40”,“-30”,“-20”,“-10”,“0”,“10”,“20”,“30”,“40”,“50”,“60”,“70”,“80”,“90”,“100”};  
> m1.setScaleLabels(scaleLabels1);  
> m1.setDisplayDigitalMeterValue(false);  
> m1.setMinInputSignal(-50);  
> m1.setMaxInputSignal(100);
> 
> m2=new Meter(this, 230,350);  
> m2.setTitle(“Pressure(kPa)2”);  
> String scaleLabels2={“-50”,“-40”,“-30”,“-20”,“-10”,“0”,“10”,“20”,“30”,“40”,“50”,“60”,“70”,“80”,“90”,“100”};  
> m2.setScaleLabels(scaleLabels2);  
> m2.setDisplayDigitalMeterValue(false);  
> m2.setMinInputSignal(-50);  
> m2.setMaxInputSignal(100);
> 
> m3=new Meter(this, 230,650);  
> m3.setTitle(“Pressure(kPa)3”);  
> String scaleLabels3={“-50”,“-40”,“-30”,“-20”,“-10”,“0”,“10”,“20”,“30”,“40”,“50”,“60”,“70”,“80”,“90”,“100”};  
> m3.setScaleLabels(scaleLabels3);  
> m3.setDisplayDigitalMeterValue(false);  
> m3.setMinInputSignal(-50);  
> m3.setMaxInputSignal(100);
> 
> }
> 
> public void draw(){
> 
> if(screen==0){  
> screenbutton = new GButton(this, 10, 10, 80, 30);  
> screenbutton.setText(“Setting”);  
> screenbutton.addEventHandler(this, “screenbutton\_click1”);  
> }  
> if(screen==1){  
> screenbutton = new GButton(this, 10, 10, 80, 30);  
> screenbutton.setText(“BACK”);  
> screenbutton.addEventHandler(this, “screenbutton\_click1”);  
> }
> 
> if (port.available()\>0){  
> String val=port.readString();  
> String list=split(val,‘,’);  
> pressglobe= int(list[0]);  
> lowlim1globe=int(list[1]);  
> uplim1globe=int(list[2]);
> 
> press2globe=int(list[3]);  
> lowlim2globe=int(list[4]);  
> uplim2globe=int(list[5]);
> 
> press3globe=int(list[6]);  
> lowlim3globe=int(list[7]);  
> uplim3globe=int(list[8]);
> 
> }  
> if(screen==0){  
> if(pressglobe\<lowlim1globe){  
> m1.setArcColor(color(254,0,0));  
> m1.setScaleFontColor(color(254,0,0));  
> }  
> if(pressglobe\>uplim1globe){  
> m1.setArcColor(color(254,0,0));  
> m1.setScaleFontColor(color(254,0,0));  
> }  
> if(pressglobe\>=lowlim1globe && pressglobe\<=uplim1globe){  
> m1.setArcColor(color(0,254,0));  
> m1.setScaleFontColor(color(0,254,0));  
> }
> 
> if(press2globe\<lowlim2globe){  
> m2.setArcColor(color(254,0,0));  
> m2.setScaleFontColor(color(254,0,0));  
> }  
> if(press2globe\>uplim2globe){  
> m2.setArcColor(color(254,0,0));  
> m2.setScaleFontColor(color(254,0,0));  
> }  
> if(press2globe\>=lowlim2globe && press2globe\<=uplim2globe){  
> m2.setArcColor(color(0,254,0));  
> m2.setScaleFontColor(color(0,254,0));  
> }
> 
> if(press3globe\<lowlim3globe){  
> m3.setArcColor(color(254,0,0));  
> m3.setScaleFontColor(color(254,0,0));  
> }  
> if(press3globe\>uplim3globe){  
> m3.setArcColor(color(254,0,0));  
> m3.setScaleFontColor(color(254,0,0));  
> }  
> if(press3globe\>=lowlim3globe && press3globe\<=uplim3globe){  
> m3.setArcColor(color(0,254,0));  
> m3.setScaleFontColor(color(0,254,0));  
> }  
> clear();  
> background(254,254,254);  
> text(pressglobe,750,200);  
> text(press2globe,750,495);  
> text(press3globe,750,795);  
> m1.updateMeter(pressglobe);  
> m2.updateMeter(press2globe);  
> m3.updateMeter(press3globe);
> 
> }  
> if(screen==1){  
> background(254,254,254);  
> textSize(20);  
> fill(0);  
> text(“Lower limit (1):”,35,200);  
> text(int(lowlim1globe),220,200);  
> text(“Upper limit (1):”,35,250);  
> text(int(uplim1globe),220,250);  
> text(“Name:”,420,120);
> 
> text(“Lower limit (2):”,35,420);  
> text(int(lowlim2globe),220,420);  
> text(“Upper limit (2):”,35,470);  
> text(int(uplim2globe),220,470);  
> text(“Name:”,420,335);
> 
> text(“Lower limit (3):”,35,640);  
> text(int(lowlim3globe),220,640);  
> text(“Upper limit (3):”,35,690);  
> text(int(uplim3globe),220,690);  
> text(“Name:”,420,553);
> 
> if(MODEglobal==0){  
> text(“\<–”,255,200);  
> }  
> if(MODEglobal==1){  
> text(“\<–”,255,250);  
> }  
> if(MODE2global==0){  
> text(“\<–”,255,420);  
> }  
> if(MODE2global==1){  
> text(“\<–”,255,470);  
> }  
> if(MODE3global==0){  
> text(“\<–”,255,640);  
> }  
> if(MODE3global==1){  
> text(“\<–”,255,690);  
> }  
> if(MODEglobal\>1){  
> MODEglobal=MODEglobal-2;  
> }  
> if(MODE2global\>1){  
> MODE2global=MODE2global-2;  
> }  
> if(MODE3global\>1){  
> MODE3global=MODE3global-2;  
> }
> 
> }  
> }
> 
> // Use this method to add additional statements  
> // to customise the GUI controls  
> public void customGUI(){  
> if(screen==1){ //screen1  
> background(254,254,254);  
> createGUI();  
> }
> 
> if(screen==2){ //screen2  
> background(254,254,254);  
> button7.setVisible(false);  
> button8.setVisible(false);  
> button9.setVisible(false);  
> button10.setVisible(false);  
> button11.setVisible(false);  
> button12.setVisible(false);  
> button13.setVisible(false);  
> button14.setVisible(false);  
> button15.setVisible(false);  
> textfield1.setVisible(false);  
> textfield2.setVisible(false);  
> textfield3.setVisible(false);
> 
> }
> 
> }
> 
> void screenbutton\_click1(GButton source, GEvent event){  
> screen++;  
> customGUI();  
> println(screen);  
> if(screen\>1){  
> screen=screen-2;  
> }  
> }

for button builder generate by G4P

> public void button7\_click1(GButton source, GEvent event) { //_CODE_:button7:829860:  
> port.write(‘a’);  
> } //_CODE_:button7:829860:
> 
> public void button8\_click1(GButton source, GEvent event) { //_CODE_:button8:462719:  
> port.write(‘b’);  
> } //_CODE_:button8:462719:
> 
> public void button9\_click1(GButton source, GEvent event) { //_CODE_:button9:376359:  
> port.write(‘c’);  
> MODEglobal++;  
> } //_CODE_:button9:376359:
> 
> public void button10\_click1(GButton source, GEvent event) { //_CODE_:button10:303933:  
> port.write(‘d’);  
> } //_CODE_:button10:303933:
> 
> public void button11\_click1(GButton source, GEvent event) { //_CODE_:button11:289312:  
> port.write(‘e’);  
> } //_CODE_:button11:289312:
> 
> public void button12\_click1(GButton source, GEvent event) { //_CODE_:button12:805311:  
> port.write(‘f’);  
> MODE2global++;  
> } //_CODE_:button12:805311:
> 
> public void button13\_click1(GButton source, GEvent event) { //_CODE_:button13:237472:  
> port.write(‘g’);  
> } //_CODE_:button13:237472:
> 
> public void button14\_click1(GButton source, GEvent event) { //_CODE_:button14:421737:  
> port.write(‘h’);  
> } //_CODE_:button14:421737:
> 
> public void button15\_click1(GButton source, GEvent event) { //_CODE_:button15:292777:  
> port.write(‘i’);  
> MODE3global++;  
> } //_CODE_:button15:292777:
> 
> public void textfield1\_change1(GTextField source, GEvent event) { //_CODE_:textfield1:812558:  
> String txt = textfield1.getText();  
> m1.setTitle(txt);  
> } //_CODE_:textfield1:812558:
> 
> public void textfield2\_change1(GTextField source, GEvent event) { //_CODE_:textfield2:374267:  
> String txt2 = textfield2.getText();  
> m2.setTitle(txt2);  
> } //_CODE_:textfield2:374267:
> 
> public void textfield3\_change1(GTextField source, GEvent event) { //_CODE_:textfield3:640877:  
> String txt3 = textfield3.getText();  
> m3.setTitle(txt3);  
> } //_CODE_:textfield3:640877:
> 
> // Create all the GUI controls.  
> // autogenerated do not edit  
> public void createGUI(){  
> G4P.messagesEnabled(false);  
> G4P.setGlobalColorScheme(GCScheme.BLUE\_SCHEME);  
> G4P.setCursor(ARROW);  
> surface.setTitle(“Sketch Window”);  
> button7 = new GButton(this, 50, 83, 107, 57);  
> button7.setText(“UP”);  
> button7.addEventHandler(this, “button7\_click1”);  
> button8 = new GButton(this, 175, 83, 107, 57);  
> button8.setText(“DOWN”);  
> button8.addEventHandler(this, “button8\_click1”);  
> button9 = new GButton(this, 300, 83, 107, 57);  
> button9.setText(“SELECT”);  
> button9.addEventHandler(this, “button9\_click1”);  
> button10 = new GButton(this, 50, 300, 107, 57);  
> button10.setText(“UP”);  
> button10.addEventHandler(this, “button10\_click1”);  
> button11 = new GButton(this, 175, 300, 107, 57);  
> button11.setText(“DOWN”);  
> button11.addEventHandler(this, “button11\_click1”);  
> button12 = new GButton(this, 300, 300, 107, 57);  
> button12.setText(“SELECT”);  
> button12.addEventHandler(this, “button12\_click1”);  
> button13 = new GButton(this, 50, 517, 107, 57);  
> button13.setText(“UP”);  
> button13.addEventHandler(this, “button13\_click1”);  
> button14 = new GButton(this, 175, 517, 107, 57);  
> button14.setText(“DOWN”);  
> button14.addEventHandler(this, “button14\_click1”);  
> button15 = new GButton(this, 300, 517, 107, 57);  
> button15.setText(“SELECT”);  
> button15.addEventHandler(this, “button15\_click1”);  
> textfield1 = new GTextField(this, 490, 97, 160, 30, G4P.SCROLLBARS\_NONE);  
> textfield1.setOpaque(true);  
> textfield1.addEventHandler(this, “textfield1\_change1”);  
> textfield2 = new GTextField(this, 490, 314, 160, 30, G4P.SCROLLBARS\_NONE);  
> textfield2.setOpaque(true);  
> textfield2.addEventHandler(this, “textfield2\_change1”);  
> textfield3 = new GTextField(this, 490, 531, 160, 30, G4P.SCROLLBARS\_NONE);  
> textfield3.setOpaque(true);  
> textfield3.addEventHandler(this, “textfield3\_change1”);  
> }
> 
> // Variable declarations  
> // autogenerated do not edit  
> GButton button7;  
> GButton button8;  
> GButton button9;  
> GButton button10;  
> GButton button11;  
> GButton button12;  
> GButton button13;  
> GButton button14;  
> GButton button15;  
> GTextField textfield1;  
> GTextField textfield2;  
> GTextField textfield3;

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [June 27, 2018, 7:57am UTC](https://discourse.processing.org/t/out-of-memory-problem/1300/2 "2018-06-27T07:57:47Z")

</div>

Hi,

Does Processing run out of memory or your Arduino?

Joseph

---

<div class="post-metadata">

**Author:** ![Mmminh](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Mmminh](https://discourse.processing.org/u/Mmminh)\
**Post date:** [June 27, 2018, 8:05am UTC](https://discourse.processing.org/t/out-of-memory-problem/1300/3 "2018-06-27T08:05:00Z")

</div>

processing is the one that run out of memory

after 10 minute the program start to get slow but if I restart the program,it’s working fine again for 10 minute  
then start to get slow and finally out of memory again

---

<div class="post-metadata">

**Author:** ![Mmminh](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Mmminh](https://discourse.processing.org/u/Mmminh)\
**Post date:** [June 27, 2018, 8:07am UTC](https://discourse.processing.org/t/out-of-memory-problem/1300/4 "2018-06-27T08:07:27Z")

</div>

this is my Arduino code

> float PressurePin=A0;  
> float PressurePin2=A1;  
> float PressurePin3=A2;  
> int MODE1=0;  
> int MODE2=0;  
> int MODE3=0;  
> float readValue;  
> float readValue2;  
> float readValue3;  
> float readValueA;  
> float readValueB;  
> float readValueC;  
> int limit1=0;  
> int limit2=0;  
> int limit3=0;  
> int limit4=0;  
> int limit5=0;  
> int limit6=0;
> 
> void setup() {  
> Serial.begin(9600);  
> pinMode(PressurePin,INPUT);  
> pinMode(PressurePin2,INPUT);  
> pinMode(PressurePin3,INPUT);
> 
> }
> 
> void loop() {
> 
> if(Serial.available()){ // GUI Parameter  
> char val = Serial.read();
> 
> if(MODE1 == 0){  
> if(val== ‘a’){ //MODE1  
> limit1=limit1+5;  
> }
> 
> if(val== ‘b’){  
> limit1=limit1-5;  
> }  
> }  
> if(MODE1 == 1){  
> if(val== ‘a’){  
> limit2=limit2+5;  
> }
> 
> if(val== ‘b’){  
> limit2=limit2-5;  
> }  
> }
> 
> if(val== ‘c’){  
> MODE1++;  
> }  
> if(MODE1\>=2){  
> MODE1=MODE1-2;  
> }
> 
> if(MODE2 == 0){  
> if(val== ‘d’){ //MODE2  
> limit3=limit3+5;  
> }
> 
> if(val== ‘e’){  
> limit3=limit3-5;  
> }  
> }  
> if(MODE2 == 1){  
> if(val== ‘d’){  
> limit4=limit4+5;  
> }
> 
> if(val== ‘e’){  
> limit4=limit4-5;  
> }  
> }
> 
> if(val== ‘f’){  
> MODE2++;  
> }  
> if(MODE2\>=2){  
> MODE2=MODE2-2;  
> }
> 
> if(MODE3 == 0){  
> if(val== ‘g’){ //MODE3  
> limit5=limit5+5;  
> }
> 
> if(val== ‘h’){  
> limit5=limit5-5;  
> }  
> }  
> if(MODE3 == 1){  
> if(val== ‘g’){  
> limit6=limit6+5;  
> }
> 
> if(val== ‘h’){  
> limit6=limit6-5;  
> }  
> }
> 
> if(val== ‘i’){  
> MODE3++;  
> }  
> if(MODE3\>=2){  
> MODE3=MODE3-2;  
> }
> 
> }
> 
> readValue = analogRead(PressurePin); //read analog value  
> readValue2 = analogRead(PressurePin2);  
> readValue3 = analogRead(PressurePin3);  
> readValueA = (((5./1023.)\*readValue)-0.03);  
> readValueB = (((5./1023.)\*readValue2)-0.03);  
> readValueC = (((5./1023.)\*readValue3)-0.03);
> 
> int pressure\_kPascal = (((readValueA/0.04)-1)-24); //Variable calculate  
> int pressure\_kPascal2 = (((readValueB/0.04)-1)-24);  
> int pressure\_kPascal3 = (((readValueC/0.04)-1)-24);  
> float pressure\_Pascal = (pressure\_kPascal_1000);  
> float pressure\_Psi = pressure\_kPascal_(0.14503773800724);
> 
> Serial.print((int)pressure\_kPascal); //sent data out  
> Serial.print(“,”);  
> Serial.print((int)limit1);  
> Serial.print(“,”);  
> Serial.print((int)limit2);  
> Serial.print(“,”);
> 
> Serial.print((int)pressure\_kPascal2);  
> Serial.print(“,”);  
> Serial.print((int)limit3);  
> Serial.print(“,”);  
> Serial.print((int)limit4);  
> Serial.print(“,”);
> 
> Serial.print((int)pressure\_kPascal3);  
> Serial.print(“,”);  
> Serial.print((int)limit5);  
> Serial.print(“,”);  
> Serial.print((int)limit6);  
> Serial.println(“,”);  
> Serial.end();  
> Serial.begin(9600);  
> delay(250);
> 
> }

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [June 27, 2018, 8:47am UTC](https://discourse.processing.org/t/out-of-memory-problem/1300/5 "2018-06-27T08:47:47Z")

</div>

Try to change the available RAM memory in File -\> Preferences -\> Increase the available RAM

 ![InkedCapture_LI](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/efb690605a42d78228451e405301e89464dc257a.jpg)

---

<div class="post-metadata">

**Author:** ![Mmminh](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Mmminh](https://discourse.processing.org/u/Mmminh)\
**Post date:** [June 27, 2018, 9:02am UTC](https://discourse.processing.org/t/out-of-memory-problem/1300/6 "2018-06-27T09:02:19Z")

</div>

it’s like extend the time before it’s getting out of memory again  
is there any way to clear the memory?

thanks for reply btw

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [June 27, 2018, 9:10am UTC](https://discourse.processing.org/t/out-of-memory-problem/1300/7 "2018-06-27T09:10:18Z")

</div>

What is precisly the error message?

---

<div class="post-metadata">

**Author:** ![Mmminh](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Mmminh](https://discourse.processing.org/u/Mmminh)\
**Post date:** [June 27, 2018, 9:25am UTC](https://discourse.processing.org/t/out-of-memory-problem/1300/8 "2018-06-27T09:25:45Z")

</div>

it’s said “OutOfMemoryError:You may need to increase the memory in preference.”

But I think I found the problem.  
I set the memory to very low and try to run the program without this command and it’s working fine

> m1.updateMeter(pressglobe);  
> m2.updateMeter(press2globe);  
> m3.updateMeter(press3globe);

but if I run the program with the command above it’s said out of memory immediately.

So,I think the meter i’ve use is take so much ram and stack their data until it’s out of memory  
is there anyway to fix this?

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [June 27, 2018, 10:02am UTC](https://discourse.processing.org/t/out-of-memory-problem/1300/9 "2018-06-27T10:02:23Z")

</div>

I find your code difficult to read without indentation, but are you really creating a new `GButton` and adding an event handler every single time `draw()` is called?!

An out of memory error is a sign you have a leak somewhere - objects are being created that are not being garbage collected, because a reference is still alive somewhere. First thing to assess is all uses of `new`. This one looks suspicious.

---

<div class="post-metadata">

**Author:** ![Mmminh](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Mmminh](https://discourse.processing.org/u/Mmminh)\
**Post date:** [June 28, 2018, 1:53am UTC](https://discourse.processing.org/t/out-of-memory-problem/1300/10 "2018-06-28T01:53:54Z")

</div>

it’s work!!  
I’ve remove adding an event handler as you said and now it’s working fine

thanks
