How to decrease virtual size of a process after cleaning all containers and using malloc_trim (0)?

Hello all
i have simple server running on linux redhat 6.1
it is build with c++
in the server i have huge std vector that holds pointers to cache objects
those cache objects holds allot of data from the DB
any way ...
in some point in time there is simple API that suppose to clean the vector
i do simple iteration over the std vector and delete the object pointers and in the end i also clean() the vector
and after all of this i execute : malloc_trim (0) that returns 1
the problem is that the virtual size of a process never decrease
BUT only the resident size do decrease fine .
the big problem when i like to load the cache again , the virtual size of a process get doubled .

how do i decrease virtual size of a process in c++/c ?
thanks

You basically need to explicitly control all memory allocation, using library calls like mmap() and munmap().

As you've found, malloc_trim() doesn't really work, because any one malloc()'d bit of memory in the wrong location in the heap will wind up pinning the entire heap anyway. That's because of the way the brk()/sbrk() calls underlying malloc()/free() work in managing the heap - the standard implementation heap of memory using brk()/sbrk() has to be a single contiguous chunk of memory that has a fixed starting point. If there is any memory in use that's deep into the allocated heap space, all the memory up to and including that in use memory can't be returned to the OS.

If this is for work, instead of spending time and money trying to solve this problem by writing what will probably be a lot of buggy code that doesn't really solve anything, just buy more RAM for you server.

Thanks for your replay
this is very problematic for me , as i can't buy more RAM
can it be i have some memory leek ?
Although the resident size do decrease fine ...