Fixed the memory leaking: in function onExit add statement "this->removeAllChildren();".