erase iterator from list in debug and release mode?
<p>I have a strange problem here. I'm trying to erase an iterator from a particle system (std::list). I erase an iterator when the particles goes out of screen. When I checked the size of the particles in debug mode, I found that they are the double compared to release mode, I don't know why.</p>

<p>Kindly find the following code</p>

<pre><code> void ParticleManager::update(std::vector&lt;ci::Vec2f&gt; masses)
    {
        int targetDifference = masses.size() - m_Targets.size();

        if (masses.size() == 1 &amp;&amp; targetDifference == 1)
        {
            addTarget();
        }
        else if (targetDifference &gt; 1)
        {
            addTarget();
        } 
        else if (targetDifference &lt; 0)
        {
            deleteTarget();
        }

        Vec2f currVec, offset;
        float fCurrLengthSquared;
        bool bAllTargetsActive = true;

        std::list&lt;Particle&gt;::iterator p = m_Particles.begin();
        while( p != m_Particles.end() ) 
        {
            p-&gt;update();

            float fMinSquaredLength = 0.0f;

            // influence of the masses
            for( int i = 0; i &lt; (int) masses.size(); ++i )
            {
                currVec = masses[i] - p-&gt;m_Position;
                fCurrLengthSquared = currVec.lengthSquared();

                if (fCurrLengthSquared &lt; ParamMgr.m_fForceMinDist * ParamMgr.m_fForceMinDist)
                {
                    fCurrLengthSquared = ParamMgr.m_fForceMinDist * ParamMgr.m_fForceMinDist;
                }

                if(fCurrLengthSquared &lt; ParamMgr.m_fForceMaxDist * ParamMgr.m_fForceMaxDist)
                {
                    offset = currVec.normalized() / (fCurrLengthSquared / 500.0f);  // 1000.0f      
                    p-&gt;m_Direction += offset * ((float) TimerMgr.getDeltaTime() * ParamMgr.m_fGravity * ParamMgr.m_fGravity );
                }

                /*if( i == 0 )
                    fMinSquaredLength = fCurrLengthSquared;

                if( fCurrLengthSquared &lt; fMinSquaredLength )
                    fMinSquaredLength = fCurrLengthSquared;*/
            }

            if( masses.size() &gt; 0 )
            {
                float fSquareColorRadius = ParamMgr.m_fColorRadius * ParamMgr.m_fColorRadius;
                if( fMinSquaredLength &gt; fSquareColorRadius )
                fMinSquaredLength = fSquareColorRadius;

                float fIntensity = 1.0f - (fMinSquaredLength / fSquareColorRadius) * 0.9f;
                //p-&gt;m_Color = ci::Color(0.0f, fIntensity, 0.0f);
                //p-&gt;m_Color = ci::Color(0.0f, 1.0f, 0.0f);
            }

            p-&gt;m_fAge += (float) TimerMgr.getDeltaTime();

            // outside the window
            if( p-&gt;m_Position.x &lt; 0.0f - m_fCollisionOffsetX || p-&gt;m_Position.x &gt; getWindowWidth() + m_fCollisionOffsetX ||
                p-&gt;m_Position.y &lt; 0.0f - m_fCollisionOffsetY || p-&gt;m_Position.y &gt; getWindowHeight() + m_fCollisionOffsetY )
            {
                p-&gt;m_bIsDead = true;
            }
            else
            { 
                // check targets
                for( std::list&lt;Target&gt;::iterator t = m_Targets.begin(); t != m_Targets.end(); t++ )
                {
                    if( t-&gt;checkParticle( p-&gt;m_Position ) )
                    {
                        p-&gt;m_ColorChange = Color( CM_HSV, t-&gt;m_fHue, t-&gt;m_fSat * 0.9f, 1.0f );
                        if( p-&gt;checkTarget( *t ) )
                        {
                            t-&gt;addParticleHit();
                        }
                    }
                    else
                    {
                        if( t != m_Targets.end() )
                        {
                            p-&gt;m_Targets.remove( *t );
                            //std::cout &lt;&lt; "Try to erase: " &lt;&lt; (*t).m_Position &lt;&lt; " from target list." &lt;&lt; std::endl;
                        }
                    }
                }
            }   

            if( p-&gt;m_bIsDead )
            {
                p = m_Particles.erase(p);

            }   
                p++;
}
</code></pre>
