From: Jonathan Wakely (cow_at_[hidden])
Date: 2004-07-06 11:19:43
On Tue, Jul 06, 2004 at 04:53:38PM +0100, jhopkin_at_[hidden] wrote:
> Daniel Frey wrote:
> > > Gennaro Prota wrote:
> > > > Does the swap trick necessarily free the memory?
> > AFAIK, yes. See <http://www.gotw.ca/gotw/054.htm>.
> The STL implementation I have been using seems to allocate a buffer on first
> insertion into any container of a given type, and frees it only when it
> feels like it (often on program shut-down).
The swap trick will free the memory used by the container.
What "free the memory" means in this case is implementation-defined.
If the impl'n uses a memory pool (as GCC's libstdc++ does) then the
memory will be returned to the pool. Returning the memory to the OS is a
different matter. With libstdc++ you can disable the pool allocator, so
that all allocations are done using "new", and so deallocations will
return the memory to the OS. I would assume other pool-based allocators
offer a similar feature.
-- "Sell your cleverness and buy bewilderment: Cleverness is mere opinion, bewilderment is intuition." - Jalal-uddin Rumi
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk