Memory leak
Closed this issue · 8 comments
Is there a worked example for periodically sending data from the yun up to parse? I tried the code below, but the board froze after a while. I used FreeMemory to look at the available memory and this seems to be the problem. I suspect I'm just not clearing the ParseCreate object correctly. Any tips?
include <Bridge.h>
include <Parse.h>
include <MemoryFree.h>
define INTERVAL 60000 // one minute in ms
ParseClient client;
static unsigned long lTimer;
void setup() {
// put your setup code here, to run once:
// Initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
// Initialize Bridge
Bridge.begin();
// Initialize Parse
client.begin("MY_KEY1", "MY_KEY2");
// initialise minute timer
lTimer = millis();
// Initialize Serial
Serial.begin(9600);
Serial.println("Initialised");
}
void loop() {
// timer
if ( (long)( millis() - lTimer ) >= 0)
{
lTimer += INTERVAL; // do it again 1 interval later
//periodic actions
// print memory state
Serial.print("freeMemory()=");
Serial.println(freeMemory());
// create and fill parse object
ParseObjectCreate create;
create.setClassName("TestData");
create.add("tStk", 550);
create.add("iPwrFc", 9.1);
// send data and get response
ParseResponse response = create.send();
// display response status
Serial.println("\nResponse for saving LogData:");
Serial.print(response.getJSONBody());
if (!response.getErrorCode()) {
String objectId = response.getString("objectId");
Serial.print("Test object id:");
Serial.println(objectId);
} else {
Serial.println("Failed to save the log data");
}
response.close();
}
}
@cjevans76 Thanks for submitting the issue. We are looking at this problem. Please stay tuned.
For reference, the available memory seems to decrease every 15 or so loops round, not every loop. So with a minute between loops, it takes c. 15 minutes to see a drop in memory and c. an hour for the system to run out of memory altogether.
@cjevans76 The fix is in this commit aae4cb3
Let us know if the problem is still existing with this fix.
@ronaldyang Thanks. I'll have a look this evening and let you know.
Looks good so far (albeit with limited testing). I'll leave it running overnight to get a bit more data.
Thanks for the quick turn-around.
Still running after 10 hours so looks fixed.
Sounds good. Closing this issue.
Please update the Starter Project Link with this fix in the Quick Start guide.