jumpingmechanic Yes, because only those lambdas store the object reference, and the object keeps them in its internal list of incoming connections along with connections to its regular methods.
This can also be verified. The following will print only one of the lambdas as object's incoming connection:
ready.connect(func(): pass)
ready.connect(func(): self)
for c in get_incoming_connections():
if c.signal == ready:
print(c.callable)
So when the object is about to be deleted, it goes through the list of its incoming connections and disconnects the callables found in that list from their corresponding signals.
You can also verify this by looking at the Object
class destructor in engine's source code. From Object::~Object()
in object.cpp.
// Disconnect signals that connect to this object.
while (connections.size()) {
Connection c = connections.front()->get();
Object *obj = c.callable.get_object();
bool disconnected = false;
if (likely(obj)) {
disconnected = c.signal.get_object()->_disconnect(c.signal.get_name(), c.callable, true);
}
if (unlikely(!disconnected)) {
// If the disconnect has failed, abandon the connection to avoid getting trapped in an infinite loop here.
connections.pop_front();
}
}
Note that it calls Callable::get_object()
: