mercredi 28 janvier 2015

Destructor not being called with smart or raw pointer

Continuing from a previous question:


On this code, the destructors for Apple and Fruit don't get called at all. I have std::cerr statements in both and there's some clean up code in Apple that doesn't run. I thought calling delete was enough? Am I doing RAII correctly? I've also replaced the raw pointer with std::unique_ptr and the same result.



int32_t Fruit::frutificate(const Settings& settings) {
Fruit *listener;
if (settings.has_domain_socket()) {
listener = new Apple(settings);
} else {
listener = new Orange(settings);
}
int r = uv_run(listener->loop, UV_RUN_DEFAULT);
delete listener;
return r;
}


Update: All classes have virtual destructors.


Aucun commentaire:

Enregistrer un commentaire