I have c++ code that I clean its containers with simple clear and delete in windows. Its working great and I can see the memory reducing nicely. But for the same code in Linux, I can't see any memory reducing. Is there any compiler flag or something that I am missing ?
I have the abstract code. Sorry I can't put more code but you can see the basic idea .
It contain map's that getting big over time and there is cleanThemALL()
method that suppose to empty them .
struct ObjectsA {
std::vector aObjects;
ObjectsA(){}
};
struct sObjects {
std::string a;
std::string b;
std::string c;
};
typedef std::map<std::string, ObjectsA> ObjectsAType;
typedef std::map<std::string, sObjects> SObjectsType;
ObjectsAType m_aObjectsATypes;
SObjectsType m_sObjectsType;
typedef std::map<std::string, CacheObject*> OCacheMap;
OCacheMap m_MyCache;
MyObject::cleanThemALL()
{
m_aObjectsATypes.clear();
m_sObjectsType.clear();;
for (OCacheMap::iterator cahceIter = m_MyCache.begin();
cahceIter != m_MyCache.end();
++cahceIter) {
// Delete the Cache.
delete (*cahceIter).second;
}
}
malloc_trim (0); // NEW only resident memory did decrease
I know that in AIX there is MALLOCOPTIONS=disclaim
AIX process memory is increasing with malloc free calls in loop
Is there such thing in Linux also ?
UPDATE
after using malloc_trim (0); the resident memory did decrease to 438m from 2.5 giga but the virtual memory still stayed the same why ?
from:
3339 test20 0 5555m 2.5g 26m S 98.7 5.3 0:42.48 MyServer.exe
to:
3339 test20 0 5555m 417m 26m S 98.7 5.3 0:52.48 MyServer.exe