By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

no mem leak but process grows with STL container

P: n/a
Hi,
I have extracted our way to use some STL containers in the following
program:

#include <iostream>
#include <string>
#include <list>
#include <deque>
#include <set>

using namespace std;

int main(int argc, char **argv)
{
// some simple pointers
int* myInt = new int;
*myInt = 7;
int* myInt2;

// the STL containers
std::list<int*> theList;
std::multiset<int*> theSet;

for ( int i = 0; i < 5000; i++ )
{
// fill the list with a number of elements
for ( int j = 0; j < 3000; j++ )
{
theList.push_back( myInt );
}

// do some insert/remove operations on the list
// and allocate some more memory
for ( int j = 0; j < 50 + i*2; j++ )
{
theList.pop_front( );
myInt2 = new int;
*myInt2 = 9;
theSet.insert( myInt2 );
theList.push_back( myInt );
}

// free all the memory except for myInt*
while ( theSet.size() > 0 )
{
delete *(theSet.begin());
theSet.erase( theSet.begin());
}

// clear the list
theList.clear();
}

// free the last bit of memory
delete myInt;
}
This program continuosly grows in size running on Solaris 2.8 with the
Sun Workshop 6.0 CC compiler. However all allocated memory is freed-
there is no memory leakage. The Sun Workshop comes with an STL
implementation from Rogue Wave.
Can anyone explain the process growth?
If this is due to memory fragmentation- why is it fragmenting? The
program is allocating memory chunks of the same size and in the same
sequence with each run of the outmost for- loop?

Thank you for your assistance.

Steffen
Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.