Total members 11895 |It is currently Mon Dec 30, 2024 6:21 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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.




Author:
Newbie
User avatar Posts: 4
Have thanks: 0 time

Please post the code?

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

msi_333 wrote:
Please post the code?

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


Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

Both !

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

#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;
}


Author:
Newbie
User avatar Posts: 4
Have thanks: 0 time

the problem is solved!


Author:
Newbie
User avatar Posts: 4
Have thanks: 0 time

how , i was think about it ?

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 7 posts ] 

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



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com