Newbie with Out of memory when using client.write()
in
Core Library Questions
•
4 months ago
Hello.
I hope someone can show me the error of my ways. It's a simple problem. I have written a sketch which takes input from the Arduino and sends it to thingspeak. I am making a post using a /GET command via client.write.
The program runs for a few hours then give out of memory. It starts off using around 25Mb, the gradually increased until I get an out of memory error
I am certain I haven't done anything silly like loading images in the draw loop.
It seems my problem is caused by creating a lot of new instances of the myClient object. Initially I had declared it in the setup routine and whilst I thought this would work fine I found that it would run once and then give a
java.net.SocketException: Software caused connection abort: socket write error
So I moved it to a function called void UpdateThingSpeak() and called it from the main loop. The code is all below
Now I get the problem where I am out of memory after a few hours. I have tried everything I can think of. Issuing a
myClient.stop();
myClient=null;
myClient = new Client(this, Server,80);
In the hope that if the old client was stopped and set to null the System.gc() would release the memory.
Please could someone help. I'm sure they will tell me I am doing something very stupid
As It doesnt seem to let me add all the code I have just included the bit with the problem
P.S Its just the bit which creates the new client in the UpdateThingSpeak() function, unless someone can spot something else obvious
Many many thanks
I hope someone can show me the error of my ways. It's a simple problem. I have written a sketch which takes input from the Arduino and sends it to thingspeak. I am making a post using a /GET command via client.write.
The program runs for a few hours then give out of memory. It starts off using around 25Mb, the gradually increased until I get an out of memory error
I am certain I haven't done anything silly like loading images in the draw loop.
It seems my problem is caused by creating a lot of new instances of the myClient object. Initially I had declared it in the setup routine and whilst I thought this would work fine I found that it would run once and then give a
java.net.SocketException: Software caused connection abort: socket write error
So I moved it to a function called void UpdateThingSpeak() and called it from the main loop. The code is all below
Now I get the problem where I am out of memory after a few hours. I have tried everything I can think of. Issuing a
myClient.stop();
myClient=null;
myClient = new Client(this, Server,80);
In the hope that if the old client was stopped and set to null the System.gc() would release the memory.
Please could someone help. I'm sure they will tell me I am doing something very stupid
As It doesnt seem to let me add all the code I have just included the bit with the problem
P.S Its just the bit which creates the new client in the UpdateThingSpeak() function, unless someone can spot something else obvious
Many many thanks
- void UpdateThingSpeak() // Formats the output and sends it as a GET request to the ThingSpeak servers
{
url = ("GET /update?key="+APIKey+"&field1="+PanelTemp+"&field2="+PoolTemp+"&field3="+ControllerMode+"&field4="+SetTempInc+"&field5="+PanelCriticalTemp+"&field6="+CumulativePumpRuntime+"&field7="+PumpsOnOff+"&status="+StatusText+"\n");
if (myClient!=null)
{
myClient.write(url);
// myClient.stop();
// myClient=null; // Destroy the object to allow System.gc() to release the memory
myClient = new Client(this, Server,80); // Create a new Client connection to the ThingSpeak Server
}
}
1