????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”?汾?? ???????????????????и???????й????????????????????????