Compilador VS2012 Problemas estranhos de desalocação de memória
Estou tendo um problema estranho com o compilador VS2012 que parece não aparecer no GCC. O processo de desalocação acaba levando minutos em vez de segundos. Alguém tem alguma opinião sobre isso? A depuração de etapas mostra um travamento perceptível nas chamadas para RtlpCollectFreeBlocks (). Eu tenho esse problema no modo de depuração e liberação. Estou executando o Windows 7 de 32 bits, mas tenho o mesmo problema em 64 bits 7.
#include "stdafx.h"
#include <iostream>
#include <stdint.h>
#include <cstdlib>
#define SIZE 500000
using namespace std;
typedef struct
{
uint32_t* thing1;
}collection;
/*
* VS2012 compiler used.
* Scenarios:
* 1) Don't allocate thing1. Program runs poorly.
* 2) Allocate thing1 but don't delete it. Program runs awesome.
* 3) Allocate thing1 and delete it. Program runs poorly.
*
* Debug or Release mode does not affect outcome. GCC's compiler is fine.
*/
int _tmain(int argc, _TCHAR* argv[])
{
collection ** colArray = new collection*[SIZE];
for(int i=0;i<SIZE;i++)
{
collection * mine = new collection;
mine->thing1 = new uint32_t; // Allocating without freeing runs fine. Either A) don't allocate or B) allocate and delete to make it run slow.
colArray[i] = mine;
}
cout<<"Done with assignment\n";
for(int i=0;i<SIZE;i++)
{
delete(colArray[i]->thing1); // delete makes it run poorly.
delete(colArray[i]);
if(i > 0 && i%100000 == 0)
{
cout<<"100 thousand deleted\n";
}
}
delete [] colArray;
cout << "Done!\n";
int x;
cin>>x;
}