• Hi Folks -

    Today, I encountered a memory leak with a simple bit of code that's interfacing with a GPS module using the GPS library. Specifically, about 2-3 blocks of memory were leaking every 5 seconds (or so) until the GPS got a 'satellite lock'. This may have something to do with how my module transmits data pre-lock, or could be a mistake that I've made (as I'm new to Espruino) . In case it's relevant, the GPS Module that I'm using is the Adafruit 'Ultimate GPS Module' with MTK3339 chipset.

    Initially, I thought the memory leak was something in my code, and I was in the process of tracking that down when the GPS got a 'lock' and the memory leak stopped. I stripped my code down to the minimum, and grabbed three process.memory() and trace() dumps, two before the 'satellite lock', and one after.

    Here's the code that I was testing this with:

    Serial4.setup(9600,{tx:C10,rx:C11});
    var gps = require("GPS").connect(Serial4, function (data) {
    		if ((data.time.substr(-2))=="00") {
    			console.log("time = "+data.time);
    			console.log("lat = "+data.lat);
    			console.log("lon = "+data.lon);
    		}
    });
    

    Immediately after uploading the code, process.memory() returned the info below. The matching trace file is called 'trace-start.txt'

    {"free":1654,"usage":146,"total":1800,"h­istory":70,"stackEndAddress":536909536,"­flash_start":134217728,"flash_binary_end­":134435300,"flash_code_start":134443008­,"flash_length":262144}
    

    A few minutes later process.memory() returned the info below. The matching trace file is called 'trace-422.txt'

    {"free":1378,"usage":422,"total":1800,"h­istory":70,"stackEndAddress":536909536,"­flash_start":134217728,"flash_binary_end­":134435300,"flash_code_start":134443008­,"flash_length":262144}
    

    Finally, the satellite locked when 576 blocks of memory had been used, and the memory leak stopped. process.memory() returned the info below. The matching trace file is called 'trace-satlock.txt'

    {"free":1224,"usage":576,"total":1800,"h­istory":88,"stackEndAddress":536909536,"­flash_start":134217728,"flash_binary_end­":134435300,"flash_code_start":134443008­,"flash_length":262144}
    

    I'd be interested in anyone's thought of ideas on this problem.

    Thanks.


    3 Attachments

About

Avatar for azrobbo @azrobbo started