Memory leaks with MQTT in agent

I have been trying to figure out why my agent code is losing data when it tries to send data from the device to an mqtt server. I have tried bracketing calls to imp.getmemoryfree() around various calls and it seems like I am losing memory during the publishing of new data to the server.

I am connecting to the server and then publishing some topics which seem to be the cause of the leak, but I don’t understand why since all the strings are local to the function. After several days of sending data the Agent runs out of memory and restarts. Any suggestions what I might be doing wrong?

    local config_topic1 = "homeassistant/sensor/duration_compressor/config";
    local config_payload1 = {
        "device_class":"duration",
        "state_topic":"homeassistant/sensor/sensorCompressor/state",
        "unit_of_measurement":"s",
        "value_template":"{{ value_json.duration}}",
        "unique_id":"compressor_duration01ae",
        "device":{
            "identifiers":[
                "compress01ae"
                ],
            "name":"Pipe Compressor"
        }
    };

 local message = mqtt_client.createmessage(config_topic1, http.jsonencode(config_payload1) , 
  {"qos": mqtt.AT_LEAST_ONCE});

    message.sendasync(function(result) {
        if (result != 0) server.error("Error code " + result);
    });

I did some tinkering and found that if I changed the qos parameter in the createmessage call from AT_LEAST_ONCE to AT_MOST_ONCE the memory leaks are gone. Looks like the messages are cached by the mqtt client even though the messages are delivered. Maybe the broker is not able to acknowledge the delivery. In any case it seems to be working for now.

FWIW I pretty much copied the example code for this library and just modified the contents of the payloads for my needs, so I did not even consider the “qos” settings since this seemed to be the recommended way to do it.