I have the following function that is called each time a user click a button :
void Foo::onCommand1Clicked(int index)
{
connect(this, &Foo::authorized, this, [=]() {
// avoid multiple connections
QObject::disconnect(this, &Foo::authorized, this, nullptr);
// do work based on "index" captured by value ( or other parameters in real code )
this->processCommand1(index);
// ..
}
});
}
Now, if the command is "authorized" ( the signal is asynchronously emitted but may also not be emitted at all), then the lambda containing the command logic is executed. Moreover, while the command is pending for authorization, the button is disabled ( preventing the function to be called )
My question is about the lambda connected to the signal and especially its parameters captured by value : Are those parameters eventually released from memory or do they accumulate into the memory stack each time the connection is done (ie the button is clicked) ?
More generally, is there any kind of "memory leak" or "continuously growing stack" in this code ?
Thank you.