title: Exc access error
body: <p>Very new to C++ and having problems returning a vector.  I put a breakpoint and the array is correct (populated with all the objects I would expect from the query).  But when it returns I get an error:
       EXC_BAD_ACCESS
  on line m_pComponentContainer->removeAll();
      from CCNode.cpp</p>
  
  <p>Which is strange since this is a base class (does NOT inherit from any kind of CC object) although I am extensively using the Cocos2dx framework, its not included in this class.</p>
  
  <p>Im fairly sure this is because something is being deallocated.  However like I said Im very new to C++ and not really sure where the problem is.  I was hoping to get a little further in development before I had to start worrying about memory management. </p>
  
  <pre><code> int numberOfCards = DatabaseHelper::getNumberOfCards();
  
  //cant be zero
  assert(numberOfCards);
  
  std::vector&lt;CardSlot&gt; returnArray(numberOfCards);
  
  sqlite3_stmt * statement;
  
  if (sqlite3_open(this-&gt;dbpath.c_str(),&amp;this-&gt;cardWarsDB) == SQLITE_OK)
  {
      const char* query_stmt = "select ID, HP, MP, AbilityText from Cards WHERE ID IN (SELECT DISTINCT cardsID FROM Deck WHERE name = 'All')";
  
      if (sqlite3_prepare_v2(this-&gt;cardWarsDB, query_stmt, -1, &amp;statement, NULL) == SQLITE_OK)
      {
          while (sqlite3_step(statement) == SQLITE_ROW)
          {
              CardSlot *aCard;
  
              const char* cardID = (const char*)sqlite3_column_text(statement, 0);
              const char* cardHP = (const char*)sqlite3_column_text(statement, 1);
              const char* cardMP = (const char*)sqlite3_column_text(statement, 2);
              const char* cardAbility = (const char*)sqlite3_column_text(statement, 3);
  
              if (cardID != NULL) {
                  std::string imageName = ".png";
                  imageName = cardID + imageName;
                  aCard = (CardSlot *)CardSlot::spriteWithFile(imageName.c_str());
              }
  
              if (cardID != NULL) {
                  aCard-&gt;cardID = std::string(cardID);
                  cocos2d::CCLog("DB returned results, cardID: %s",aCard-&gt;cardID.c_str());
              }
              if (cardHP != NULL) {
                  aCard-&gt;cardHP = std::string(cardHP);
                  cocos2d::CCLog("DB returned results, cardHP: %s",aCard-&gt;cardHP.c_str());
              }
              if (cardMP != NULL) {
                  aCard-&gt;cardMP = std::string(cardMP);
                  cocos2d::CCLog("DB returned results, cardMP: %s",aCard-&gt;cardMP.c_str());
              }
              if (cardAbility != NULL) {
                  aCard-&gt;cardAbility = std::string(cardAbility);
                  cocos2d::CCLog("DB returned results, cardAbility: %s",aCard-&gt;cardAbility.c_str());
              }
  
              numberOfCards--;
  
              returnArray[numberOfCards] = *aCard;
  
          }
          sqlite3_finalize(statement);
      }
      sqlite3_close(this-&gt;cardWarsDB);
      return returnArray;
  }
  </code></pre>
  
  <p>Here is a screenshot of the stack trace.  I was just looking at it, and it seems that it is the CardSlot objects are the culprits.
  But still dont know how to "retain" them, but Ill look at some Cocos documentation.</p>
  
  <p><img src="https://i.stack.imgur.com/eh6LN.png" alt="enter image description here"></p>
  
  <p><a href="https://stackoverflow.com/a/658152/530933">NOTE1</a></p>