The unused initialization code will be freed as soon as the memory is needed for other purposes. (It will be backed by files from which it is read.)
The memory paging mechanisms on Linux are well designed and have been tested for years. It is rare you would want to swap any process out of memory. This would result in heavy paging activity any time the swapped process is scheduled for execution.
If you truly need the memory from the other applications, you have too little memory. You can prevent the other programs from executing by sending them a STOP
signal with the kill
command. Be careful which programs you stop or you could lock yourself out of the system.
If you are experiencing large pauses during startup of your process, consider using sar
to determine where the bottleneck is. You can also use top
to determine which process are being paged or swapped heavily. Don't be surprised if your process shows up as the problem.
I've run servers which were severely starved for memory. To perform startups, it was essential to limit the number of processes starting at any one time. Process start almost instantaneously even if memory is far over-committed.
If you really want to force everything possible out of memory you could write a program that allocates the desired amount of memory and continually writes to each page of the allocated memory for a few loops. It will experience all the issues you want to avoid.