[Question] Must MQTTAsync_destroy be called after the disconnect operation completed?
Closed this issue · 2 comments
Hi,
In paho.mqtt.c example, MQTTAsync_destroy is called after disconnect operation completed: https://github.com/eclipse/paho.mqtt.c/blob/master/src/samples/MQTTAsync_subscribe.c
while (!disc_finished)
{
#if defined(_WIN32)
Sleep(100);
#else
usleep(10000L);
#endif
}
destroy_exit:
MQTTAsync_destroy(&client);
And paho.mqtt.cpp example is also called after disconnect operation completed:https://github.com/eclipse/paho.mqtt.cpp/blob/master/src/samples/async_consume_v5.cpp
cli.stop_consuming();
cli.disconnect()->wait();
And I have two questions:
1、Must MQTTAsync_destroy be called after the disconnect operation completed?
2、Must MQTTAsync_destroy be called in the same thread of call MQTTAsync_create?
Best Regards.
You only need to call destroy if you want to clean up the resources used. If the application ends right away after the disconnect, or you want to reconnect later then you might not want to call destroy.
You can use a different thread, but you'll need to make sure the client object isn't still being used in another thread.
Question answered.