Out of memory problem

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;

Hi,

Does Processing run out of memory or your Arduino?

Joseph

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

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_kPascal1000);
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);

}

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

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

What is precisly the error message?

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?

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.

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

thanks