Maybe someone has an answer to the strange memory usage of the following program:
#include <iostream>
#include <vector>
#define SIZE 25
#define FULL SIZE * SIZE * SIZE * SIZE * SIZE * SIZE
class T {
public:
std::vector<char*> test[FULL];
};
int main(int argc, char** argv) {
std::cout << "creating test object..." << std::endl;
std::cout.flush();
T* t = new T();
std::cout << "creating strings..." << std::endl;
std::cout.flush();
for (int i = 0; i < FULL; i++) {
char* newChar = new char[50];
t->test[i].push_back(newChar);
}
std::cout << "freeing strings..." << std::endl;
std::cout.flush();
for (int i = 0; i < FULL; i++) {
delete[] t->test[i].front();
t->test[i].pop_back();
}
std::cout << "freeing test object..." << std::endl;
std::cout.flush();
delete t;
return 0;
}
Note: This program uses nearly 80 GB ram!
The problem now: the ram usage is getting more and more which is correct. But the memory usage is not getting less when strings are beeing freed or the object t is deleted.
Aucun commentaire:
Enregistrer un commentaire