title: Cocos 2dx game increasing in memory every time a scene transition occurs
body: <p>I am making a cocos 2dx game. But each time the memory increases with every level transition. For debugging purposes I am calling the same scene again and again on touch event. Each level is generated by changing the parameters for the folowing code. Initially I thought that the memory was increasing because there were more objects in the higher levels, but even when calling the same level, memory occupied is increasing. </p>
  
  <pre><code>#include "GameScene.h"
  #include "MainMenuScene.h"
  #include "GameOverScene.h"
  #include "Levels.h"
  #define COCOS2D_DEBUG 1
  
  USING_NS_CC;
  
  float theta=0;
  int r=0;
  int levelNo=0;
  int controlable=0;      // flag to check if user can controll the ball or not
  int rMax=0;             // max radius of circle
  float objectTime;     // stores the inverse of speed
  int secondCount=0;    // second han value in the timer
  int minuteCount=0;   //minute hand clock in the timer
  float obstacleSpeed=0;
  Label *timer;
  
  GameScene::~GameScene()
  {
  
  
      rotationPoint-&gt;removeAllChildrenWithCleanup(true);
      obstacleRotationPoint-&gt;removeAllChildrenWithCleanup(true);
         this-&gt;removeAllChildrenWithCleanup(true);
  
  }
  
  Scene* GameScene::createScene(int level)
  {
      // 'scene' is an autorelease object
      auto scene = Scene::create();
      controlable=0;
      r=0;
      theta=0;
      // 'layer' is an autorelease object
      levelNo=level;
      rMax=levels[levelNo].ringCount * 15;    //setting various parameters
      obstacleSpeed =levels[levelNo].obstacleSpeed;
      objectTime=1.0/levels[levelNo].speed;
      secondCount=0; minuteCount=0;
      auto layer = GameScene::create();
  
      // add layer as a child to scene
      scene-&gt;addChild(layer);
  
  
      // return the scene
      return scene;
  }
  
  // on "init" you need to initialize your instance
  
  bool GameScene::init()
  {
      //////////////////////////////
      // 1. super init first
      if ( !Layer::init() )
      {
          return false;
      }
      controlable=0;
      distance=rMax;
      visibleSize = Director::getInstance()-&gt;getVisibleSize();
      Vec2 origin = Director::getInstance()-&gt;getVisibleOrigin();
  
  #if COMPILE_FOR_MOBILE == 1
      auto listener = EventListenerTouchOneByOne::create();
      listener-&gt;setSwallowTouches(true);
  
      listener-&gt;onTouchBegan = CC_CALLBACK_2(GameScene::onTouchBegan, this);
  
      _eventDispatcher-&gt;addEventListenerWithSceneGraphPriority(listener, this);
  
  #endif
  
      goal = DrawNode::create();
      goal-&gt;drawDot(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y), 5, Color4F(100,0,0,1));
      this-&gt;addChild(goal,1);          // drawing the goal
  
  
      rotationPoint = Node::create();
      rotationPoint-&gt;setPosition(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y);
      this-&gt;addChild(rotationPoint, 2);
  
  
      //Setting the exit button
      auto exitLabel = Label::createWithTTF("Exit","fonts/Marker Felt.ttf",10);
      exitButtonWidth=exitLabel-&gt;getContentSize().width;
      exitButtonHeight=exitLabel-&gt;getContentSize().height;
      exitLabel-&gt;setPosition(Point(visibleSize.width-exitButtonWidth,visibleSize.height-exitButtonHeight));
      this-&gt;addChild(exitLabel);
  
  
      //setting the clock
      timer = Label::createWithTTF("00:00","fonts/Marker Felt.ttf",10);
      timer-&gt;setPosition(Point(timer-&gt;getContentSize().width,visibleSize.height-timer-&gt;getContentSize().height));
      this-&gt;schedule(schedule_selector(GameScene::updateClock),1.0f);  //scedule to call upDateClock function every 1.0 sec
      this-&gt;addChild(timer);
  
      obstacleRotationPoint = Node::create();
      obstacleRotationPoint-&gt;setPosition(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y);
      this-&gt;addChild(obstacleRotationPoint, 3);
  
  
      float theta=0;
  
      snake[0] = DrawNode::create();
      snake[0]-&gt;drawDot(Vec2(0,0),3,Color4F(100,110,0,1));
      theta+=2*M_PI/150;
      //this-&gt;addChild(snake[0],2);
  
      rotationPoint-&gt;addChild(snake[0]);
        // fixedPoint-&gt;addChild(snake[0]);
  
  
     //loop to draw the concentric circles
  
     for(r=15;r&lt;=rMax;r+=15)
      {
        for(theta=0;theta&lt;=2*M_PI;theta+=2*M_PI/r){
            pathNode = DrawNode::create();
            pathNode-&gt;drawDot(Vec2(r*cos(theta)+origin.x+visibleSize.width/2,r*sin(theta)+origin.y+visibleSize.height/2),1,Color4F(0,0,10,1));
            //pathNode-&gt;autorelease();
             this-&gt;addChild(pathNode,1);
            //this-&gt;removeChild(pathNode);
          }
      }
  
      controlable=0;
      this-&gt;scheduleUpdate();
      return true;
  }
  
  bool GameScene::onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *event)
  {   // check if exit button region was clicked
      _eventDispatcher-&gt;removeAllEventListeners();
      auto scene = GameScene::createScene(levelNo);
      Director::getInstance()-&gt;replaceScene(scene);
      return true;
  }
  
  
  
  //function updates every frame
  void GameScene::update(float dt){
  }
  </code></pre>
  
  <p>The last part in the init function where I need to add pathNode is increasing my memory requirement everytime I transition a scene. I believe  I am releasing everything in my destructor.</p>