title: stringstream << operator consuming a lot of memory inside a loop
body: <p>I have an update method that is like an infinite loop because is run every frame. Inside this method I get a float and I have to convert it to an string every frame to post the socore in the screen.</p>
  
  <p>I'm using the &lt;&lt; operator that allows me to copy the float to an stringstream and then, i use the str() function to get the string value of the stream.</p>
  
  <p>In the header file I declared <code>scoreString</code>, <code>actualScore</code> and <code>scoreLabel</code>.</p>
  
  <pre><code>update(dt){
      actualScore += combo;
      scoreString.str("");
      scoreString &lt;&lt; actualScore;
      scoreLabel-&gt;setString(scoreString.str());
      scoreString.clear();
  }
  </code></pre>
  
  <p><code>actualScore</code> is the float that I want to convert to a string. For that purpuse, I use the scoreString object that is an <code>stringstream</code>. To recycle this <code>stringstream</code> I use the <code>str("")</code> function that set the value to nothing, and so I don't have to create the object every time that the loop is run.</p>
  
  <p>This code it's used inside a cocos2dx application, and it's runned in IOS and android devices. I'm getting out of memory only in the android devices.</p>
  
  <p>Here is my logCat output, but I think that it wouldn't show nothing new.</p>
  
  <pre><code>01-12 15:35:25.271: D/dalvikvm(13948): GC_FOR_ALLOC freed 297K, 6% free 9580K/10160K, paused 20ms, total 20ms
  01-12 15:35:25.321: D/dalvikvm(13948): GC_FOR_ALLOC freed 297K, 6% free 9580K/10160K, paused 20ms, total 20ms
  01-12 15:35:25.371: D/dalvikvm(13948): GC_FOR_ALLOC freed 297K, 6% free 9580K/10160K, paused 21ms, total 21ms
  01-12 15:35:25.421: D/dalvikvm(13948): GC_FOR_ALLOC freed 297K, 6% free 9580K/10160K, paused 19ms, total 19ms
  01-12 15:35:25.472: D/dalvikvm(13948): GC_FOR_ALLOC freed 297K, 6% free 9580K/10160K, paused 18ms, total 18ms
  01-12 15:35:25.522: D/dalvikvm(13948): GC_FOR_ALLOC freed 297K, 6% free 9580K/10160K, paused 14ms, total 14ms
  01-12 15:35:25.572: D/dalvikvm(13948): GC_FOR_ALLOC freed 298K, 6% free 9581K/10160K, paused 15ms, total 16ms
  ...
  </code></pre>
  
  <p><strong>EDIT</strong> 
  I changed the code to the suggestions make in comments, but it didn't work. Also I change the while(true) by an update(dt) that is the real method that run this piece of code.</p>
  
  <p><strong>EDIT 2</strong>
  Here is the sprintf version, as I say, this also consumes a lot of memory. Also I changed the type of actualScore to int. On the header file I declared score as <code>char score[16];</code></p>
  
  <pre><code>update(dt){
      actualScore += combo;
      sprintf(score, "%d", actualScore);
      scoreLabel-&gt;setString(score);
  }
  </code></pre>