I am working a c# - c++ (manage) mix project and we realize there are memory leaks in our project, so I searched and found out, destructor of c++ part never called so I wrote a piece of code to free memories. Now I can see program growing slower in memory (there are more memory leaks), but the problem is, in c# part program start to crash because of "out of memory exception". In operation such as
double []k = new double[65536];
Memory usage of program normally seems 400-500mb but it crashed.
OS : win server 2003
Memory : 4 GB
OS should let program to grow nearly 1200 mb but after I wrote the free memory part it start to crash 400-500mb.
 
I called this c++ func from the c# part to free memories
freeMemories()
{
   if(!mIsAlreadyFreedMemory)
   {
      mIsalreadyFreedMemory = true;
      _aligned_free(pointerA);
      _aligned_free(pointerB);
       ....
    }
}
Why it cannot take new memory, Program can not take the released memory again?
 
    