- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- vector(STL) doesn't release memory
Operating System - Linux
1753365
Members
6017
Online
108792
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2007 03:41 AM
10-31-2007 03:41 AM
vector(STL) doesn't release memory
HP-Unix 11.2
aCC 5.5
I use lots of vector(STL vector) in my source code to store the object return from database. Recently I find an issue that the vector doesn't release its memory even leaves its scope. But the issue doesn't rise at linux platform(Redhat AS3, gcc 3.2). Someone side that the vector will keep some memory as memory pool till the process die. But it seem to can't answer my question. My program can keep memory even more than 1G. How big a pool!??
I want to know why and how can I fix the problem.
My testing code is as below:
testFun()
{
string str = "aaaaaaaa";
vector aVect;
for(long i=0;i<1024*1024;i++)
{
aVect.push_back(str);
}
aVect.clear();
vector().swap(aVect);
}
int main()
{
for(int i=0;i<1024;i++)
{
testFun();
}
}
The source code above will let the memory of process rise and won't free it till the process out of life(HP-Unix 11.2, aCC 5.5).
The issue won't rise at linux(Redhat AS3, gcc 3.2)
aCC 5.5
I use lots of vector(STL vector) in my source code to store the object return from database. Recently I find an issue that the vector doesn't release its memory even leaves its scope. But the issue doesn't rise at linux platform(Redhat AS3, gcc 3.2). Someone side that the vector will keep some memory as memory pool till the process die. But it seem to can't answer my question. My program can keep memory even more than 1G. How big a pool!??
I want to know why and how can I fix the problem.
My testing code is as below:
testFun()
{
string str = "aaaaaaaa";
vector
for(long i=0;i<1024*1024;i++)
{
aVect.push_back(str);
}
aVect.clear();
vector
}
int main()
{
for(int i=0;i<1024;i++)
{
testFun();
}
}
The source code above will let the memory of process rise and won't free it till the process out of life(HP-Unix 11.2, aCC 5.5).
The issue won't rise at linux(Redhat AS3, gcc 3.2)
- Tags:
- heap usage
- vector
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2007 03:50 AM
10-31-2007 03:50 AM
Re: vector(STL) doesn't release memory
This is normal and expected behavior and typical for most flavors of UNIX. Eventhough a destructor is invoked, the freed memory is placed on the process's heap for subsequent use by the same process. The actual memory footprint does not shrink.
The underlying system call, sbrk(), does allow for a negative growth so that memory could be returned to the system. Newer versions of the malloc(), calloc(), and realloc() functions can actually return memory to the system under very strict conditions --- if the free()'ed block was the last allocated.
UNIX ain't Linux so it is unrealistic to expect Linux behavior.
The underlying system call, sbrk(), does allow for a negative growth so that memory could be returned to the system. Newer versions of the malloc(), calloc(), and realloc() functions can actually return memory to the system under very strict conditions --- if the free()'ed block was the last allocated.
UNIX ain't Linux so it is unrealistic to expect Linux behavior.
If it ain't broke, I can fix that.
- Tags:
- brk
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP