Memory Leak In this function?
-
BOOL GetHistory() { STATURL url; CString strUrl; ULONG uFetched; IUrlHistoryStg2Ptr history; IEnumSTATURLPtr enumPtr; if(FAILED(CoCreateInstance(CLSID_CUrlHistory, NULL, CLSCTX_INPROC_SERVER, IID_IUrlHistoryStg2,(void**)&history))) { return false; } if(FAILED(history->EnumUrls(&enumPtr))) { history->Release(); return false; } while(SUCCEEDED(enumPtr->Next(1,&url,&uFetched))) { if(uFetched==0) break; } history->Release(); return true; } if I set a timer to call the function ,the memory leak if I delete while(SUCCEEDED(enumPtr->Next(1,&url,&uFetched))) { if(uFetched==0) break; } memory is good ! why? thanks!
-
BOOL GetHistory() { STATURL url; CString strUrl; ULONG uFetched; IUrlHistoryStg2Ptr history; IEnumSTATURLPtr enumPtr; if(FAILED(CoCreateInstance(CLSID_CUrlHistory, NULL, CLSCTX_INPROC_SERVER, IID_IUrlHistoryStg2,(void**)&history))) { return false; } if(FAILED(history->EnumUrls(&enumPtr))) { history->Release(); return false; } while(SUCCEEDED(enumPtr->Next(1,&url,&uFetched))) { if(uFetched==0) break; } history->Release(); return true; } if I set a timer to call the function ,the memory leak if I delete while(SUCCEEDED(enumPtr->Next(1,&url,&uFetched))) { if(uFetched==0) break; } memory is good ! why? thanks!
You must free STATURL.pwcsUrl and STATURL.pwcsTitle after each call to enumPtr->Next. MSDN says so. Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
-
You must free STATURL.pwcsUrl and STATURL.pwcsTitle after each call to enumPtr->Next. MSDN says so. Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
-
don't you do it like this ?
delete STATURL.pwcsUrl;
delete STATURL.pwcsTitle;
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
I try like this: delete STATURL.pwcsUrl; delete STATURL.pwcsTitle; but I get an excetion!
-
LPMALLOC lpMalloc; CoGetMalloc(1, &lpMalloc); lpMalloc->Free(url.pwcsUrl); lpMalloc->Free(url.pwcsTitle); lpMalloc->Release();
orCoTaskMemFree(url.pwcsUrl); CoTaskMemFree(url.pwcsTitle);
The two methods are analogous (actully, identical, CoTaskMemFree calls CoGetMalloc and IMalloc->Free). Add error handling for flavor. Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music" -
LPMALLOC lpMalloc; CoGetMalloc(1, &lpMalloc); lpMalloc->Free(url.pwcsUrl); lpMalloc->Free(url.pwcsTitle); lpMalloc->Release();
orCoTaskMemFree(url.pwcsUrl); CoTaskMemFree(url.pwcsTitle);
The two methods are analogous (actully, identical, CoTaskMemFree calls CoGetMalloc and IMalloc->Free). Add error handling for flavor. Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"