问题遇到的现象和发生背景
VS2022 使用MFC CStringArray使用setatgrow添加元素,使用removeall()之后在使用setatgrow()添加元素,频繁操作内存一直增长,使用setsize()、FreeExtra()还是会增长,只是增长变得缓慢了。
问题相关代码,请勿粘贴截图
{
m_arLabels.GetAt(i)->m_strTextArray.RemoveAll();
m_arLabels.GetAt(i)->m_strTextArray.FreeExtra();
for (int k = 0; k< 3; k++)
{
CString strValue = _T("");
if (k== 0)
strValue.Format(_T("%d"), i);
else if (k == 1)
strValue = CString(pszNames[i % 5]);
else
strValue.Format(_T("%d"), rand());
m_arLabels.GetAt(i)->m_strTextArray.Add(strValue);
}
我想要达到的结果
解决内存增长的问题