Welcome to WebProNews Breaking eBusiness and Search News
Advertise | Newsletter | Sitemap | News Feeds News Feed 
Part of the iEntry network iEntry inc. 

Free/Delete Not Returning Memory To OS?

Dean Michael Berris
Expert Author
Published: 2011-03-17

WebProNews RSS Feed

As I do keep tabs on what's going on with C++ around the web, I chanced upon this short and succinct article about ‘free' and ‘delete' not returning memory to the OS from Thought Garage which starts with:

When you call free() or delete(), it will NOT really release any memory back to OS. Instead, that memory is kept with the same process until it is terminated. However, this memory can be reused for any future allocations by the same process.

It's interesting to read this and remember some horror stories I saw with memory usage on long-running processes (HTTP servers to be exact). Is this true then?

I decided to check first by reading the documentation for libc's free:

Occasionally, free can actually return memory to the operating system and make the process smaller. Usually, all it can do is allow a later call to malloc to reuse the space. In the meantime, the space remains in your program as part of a free-list used internally by malloc.

That's not very clear although it mentions that occasionally memory will be returned to the OS. I dug a little deeper by looking at other malloc/free family of functions and saw 'mallopt', and that you can actually change the way malloc/free behave (especially if you're using GNU libc - pointers about other platform implementations would be helpful). One option that is interesting to look at is M_TRIM_THRESHOLD which:

This is the minimum size (in bytes) of the top-most, releasable chunk that will cause sbrk to be called with a negative argument in order to return memory to the system.

So if you really want to control when you return memory to the operating system, then tuning malloc with mallopt would be a good option.

Another thing that came to mind when doing C++ development and when you know you will be making a lot of allocations of small objects from the heap is that object pools make a lot of sense. One popular implementation of an object pool is Boost.Pool - although there are some issues with using Boost.Pool's standard allocator interface from my experience, using Boost.Pool's object_pool and pool interface yield desirable results in situations where performance matters.

One way of getting around the Boost.Pool issues with the standard containers is by using Boost.Interprocess containers to use a stateful allocator instance that deals with a user-controlled Boost.Pool object_pool.

Do you have any tips with better memory management when developing C++ applications?


View All Articles by Dean Michael Berris

Receive Our Daily Email of Breaking eBusiness News

About the Author:
Dean Michael Berris is the writer of C++ Soup! C++ Soup is a blog about what’s new, up-coming, and what’s going on with C++. C++ Developer with years of experience building high performance applications and implementing multi-threaded highly scalable systems.

WebProNews RSS Feed

More Top News Articles

Contact WebProNews


The official blog of WebProNews.

Go to WebProBlog

Targeted Information for Business
WebProNews is part of the iEntry network

Internet Business: Marketing: Small Business:
WebProNews MarketingNewz SmallBusinessNewz
WebProWorld AdvertisingDay PromoteNews
EcommNewz SalesNewz EntrepreneurNewz

Software: Search Engines: Web Design:
WebMasterFree Jayde B2B DesignNewz
NetworkingFiles SearchZA FlashNewz
SecurityConfig SearchNewz WebSiteNotes

Developer: IT Management: Security:
DevWebPro ITManagement SecurityProNews
DevNewz SysAdminNews SecurityConfig
TheDevWeb NetworkingFiles NetworkNewz

The iEntry Network consists of over 100 web publications reaching millions of Internet Professionals. Contact us to advertise.

 Advertise | Contact Us | Corporate | Newsletter | Sitemap | Submit an Article | News Feeds
 WebProNews is an iEntry, Inc. ® publication - $line) { echo $line ; } ?> All Rights Reserved
Ten most recent posts.

Featured Software

About WebProNews
WebProNews is the number one source for eBusiness News. Over 5 million eBusiness professionals read WebProNews and other iEntry business and tech publications.

WebProNews provides real-time coverage of internet business.

Free Email Newsletters:
WebProNews SearchNewz
WebProWorld DevWebPro
Marketing SecurityNews
Plus over 100 other newsletters!

Send me relevant info on products and services.

iEntry.com WebProWorld RSS Feed WebProWorld Contact WebProNews Print Version Email a friend Bookmark us SearchBrains.com SearchBrains RSS Feed