????wikipedia?????????????泄?????????????校????泄????????????????????未????????????????????????????泄?????????????????????????????贸??????????????????????????????????????????????????????????????????????
??????????????????????????泄?????未???????????????????? bug?? ???????蔚?小?????泄?????????????泄?????????????泄?????????????????????????????????????????????????????????????t??? ????????泄??????????????????妫�??????????????????????????????????????????? ???????????????泄??????????????????????
???????泄????????????????????????????????????????????????????锟�???????????姹�????????????????璞�??????????????????贸???????????泄???????????????????????????渭???????????????????校??????贸??????????????????????????????????????????械???贸????械????泄???????????????
??????????????????泄???????????????
???????????泻?????????????????????????????????????妫�???????????????????????????????械?????????些???????????泻??????????????????
?????渭???姹�???????????绲�(t菕ng)????????????????????????
???????????????未????????妫�???绻�????妫�?????????????????????
????泄?????????????????
????泄?????????????蟹?????
?????????????????????????????携?璞�?校?
?????????????????????娌�????????????????????AmigaOS?????????????????????????????????
???????????????????????????????渭?????泄?????
#include <stdlib.h>
#include <iostream>
using namespace std;
void GetMemory(char *p?? int num)
{
p = (char*)malloc(sizeof(char) * num);//???new??????????
}
int main(int argc??char** argv)
{
char *str = NULL;
GetMemory(str?? 100);
cout<<"Memory leak test!"<<endl;
//???main?写???while???????GetMemory
//?????????煤?????
//while(1){GetMemory(...);}
return 0;
}
????????胁??????????????????????貌??????????????????????????????????????????
????2??Windows???渭????泄????
????2.1??????????????泄?????
????Windows??????Visual Studio ???????? C ????? (CRT) ????????????????????泄?????效???????????????锟�???????????CRT???????????????????????????????????眉????????????????????????????????????????????????泄?????vs??????????????????锟�?
????STEP1????????邪?????????? ??#include ??????????????????? ????????????????????????????????????????
????#define _CRTDBG_MAP_ALLOC
????#include <stdlib.h>
????#include <crtdbg.h>
??????????? crtdbg.h???? malloc ?? free ???????????????姹�???? _malloc_dbg ?? _free_dbg????????????????????????????? ???????????姹�???????卸?????_DEBUG???蟹????? ?????姹�???????? malloc ?? free ??????
????#define ??浣� CRT ?????????姹�????????“Debug”?姹�?? ???????????????????懈???????泄????????????????????????