I have a sidebar in my modeleditor, and there's a label "Memory usage". In the update function i do something like:
void cVmSidebar::onUpdate(){
static wstringstream wInfo;
wInfo.str("");
wInfo.clear();
wInfo<<(cCore::GetAllocatedMemory() / 1024)<<"Kb";
lpMemLabel->bSetWindowText(wInfo.str().c_str());
}
If i do so, allocated memory runs up and up and up... if i use something like:
void cVmSidebar::onUpdate(){
char buffer[10];
_itoa_s((cCore::GetAllocatedMemory()/1024), buffer, 10);
lpMemLabel->bSetWindowTextA(buffer);
}
it runs good, memory don't increases. Doesn't matter if i type "static wstringstream wInfo" or "wstringstream wInfo".
cCore::GetAllocatedMemory:
size_t cCore::GetAllocatedMemory(){
HANDLE process = GetCurrentProcess();
PROCESS_MEMORY_COUNTERS meminfo;
if (GetProcessMemoryInfo(process, &meminfo, sizeof(PROCESS_MEMORY_COUNTERS))){
return meminfo.WorkingSetSize;//PagefileUsage;
}
return 0;
}
Is this a memory leak? And... why is this happening?