Switch to full style
For C/C++ coders discussions and solutions
Post a reply

problem with memory alocation

Wed Dec 12, 2012 1:10 pm

Hi to all!

Some time ago I have a strange problem with memory alocation (while using stl containers). I attached c++ source files (ok.cpp and fail.cpp). In ok.cpp everything work "almost" fine, I mean almost all the memory is released after deleting all the elements. BUT the number of 500*8 elements on the list seems to be a limit somehow. In fail.cpp, the number of elements on the list is 500*16 (the size of single element is decreased to 1024*64 from 1024*128). Here, after deleting all the elements of the list and going out of the scope where the list is declared, there is no memory released.
1 How is that possible?
2 What to do? How to fix it?
Thanks for ANY help.



Re: problem with memory alocation

Sun Dec 16, 2012 10:00 pm

Please post the code?

Re: problem with memory alocation

Mon Dec 17, 2012 3:35 pm

msi_333 wrote:Please post the code?

+
Part of the code or the debugger report :confused: this is important!

Re: problem with memory alocation

Tue Dec 18, 2012 1:27 pm

Both !

Re: problem with memory alocation

Tue Dec 18, 2012 3:05 pm

#include <list>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

using namespace std;

int main(int argc, char *argv[])
{
{
printf ("Allocating\n");
list<char*> testList;
for (int a = 0; a < 500 * 16; a++)
{
char *test = new char[1024 * 64];
memset(test, 'A', 1024 * 64);
testList.push_back(test);
}
usleep(10000000);

printf ("Deallocating\n");
for (list<char*>::iterator a = testList.begin(); a != testList.end(); a++)
{
delete[] *a;
}
}

usleep(10000000);

return 0;
}
ok.cpp C++ 543 bytes

#include <list>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

using namespace std;

int main(int argc, char *argv[])
{
{
printf ("Allocating\n");
list<char*> testList;
for (int a = 0; a < 500 * 8; a++)
{
char *test = new char[1024 * 128];
memset(test, 'A', 1024 * 128);
testList.push_back(test);
}
usleep(10000000);

printf ("Deallocating\n");
for (list<char*>::iterator a = testList.begin(); a != testList.end(); a++)
{
delete[] *a;
}
}

usleep(10000000);

return 0;
}

Re: problem with memory alocation

Wed Dec 19, 2012 5:09 pm

the problem is solved!

Re: problem with memory alocation

Wed Dec 19, 2012 5:25 pm

how , i was think about it ?

Post a reply
  Related Posts  to : problem with memory alocation
 GDI memory leaks detection     -  
 C++ & Java memory management!!     -  
 MATLAB clear memory     -  
 Memory leak detection in C++     -  
 subtract number from memory locations     -  
 Latest XML parsing/memory usage benchmark     -  
 i have problem     -  
 MVC problem....     -  
 Skymiles [3.04] little? problem     -  
 Paging problem in php     -