Hi chromium-dev team,
I have a following class:
class Adapter {
public:
Adapter() : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {}
void Start() {
Poll();
}
private:
friend class base::RefCounted<Adapter>;
~Adapter() {}
void Poll() {
// Polling task.
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&Adapter::Poll, weak_ptr_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(500));
}
base::WeakPtrFactory<Adapter> weak_ptr_factory_;
};
which basically performs polling task once Start() is called. Let's say Poll() is run and Adapter::Poll of the adapter instance is queued into the current message loop, and then the adapter instance is destroyed by having no more references to it. Does message loop crash due to orphaned pointer, or does message loop handle it gracefully by checking the orphaned pointer and not running it? I made a test to verify this and it seems the message loop handles it gracefully, but I'd like to hear from the expert.
Thanks,
Youngki