Hi Iam working on a cocos2dx framework with cpp. I am facing memleak on a function where I use new keyword to initialize a class. Here I have a base class for all the popup in my game. I would like to make a popup from the base popup class inheriting from it. And adding the new popup as a child of a scene. The problem is when I initialize the new popup class on the stack, I couldnot call other functions which is in the new popup class. So i initialized my new popup class in heap using new keyword. Iam also deleting the instance on a function called close popup. I also saw that when clearing Iam calling the delete on the correct pointer. But my precommit says thats a memeleak. Can someone sugeest ideas? Here's my code
# Newpopup.cpp extends BasePopup
views::BasePopup* NewPopup::createPopup() {
popup = BasePopup::createPopup(Size(400, 500));
return popup;
}
void NewPopup::cleanPopup() {
popup->removeFromParent();
delete this;
}
Adding the new popup to a scene in another Scene class
# Adding to scene
void MainScene::getNewPopup() {
NewPopup* NewPopup = new NewPopup();
this->addChild(NewPopup);
}
Here am I doing the correct delete?