fix memory leak part 3

master
FengJungle 2020-11-29 13:40:29 +08:00
parent b287aed6cc
commit ed859f709e
8 changed files with 50 additions and 6 deletions

View File

@ -7,5 +7,6 @@ int main()
controller->pathPlanning(); controller->pathPlanning();
system("pause"); system("pause");
delete controller;
return 0; return 0;
} }

View File

@ -14,10 +14,14 @@ int main()
printf("++++++++++++++++++++++++++++++++++\n"); printf("++++++++++++++++++++++++++++++++++\n");
//Jungle想在这个手机上玩游戏B //Jungle想在这个手机上玩游戏B
delete game;
game = new GameB(); game = new GameB();
phone->setupGame(game); phone->setupGame(game);
phone->play(); phone->play();
delete phone;
delete game;
system("pause"); system("pause");
return 0; return 0;
} }

View File

@ -21,7 +21,6 @@ int main()
office5 = new AdminOffice("行政办公室"); office5 = new AdminOffice("行政办公室");
office6 = new DeanOffice("教务办公室"); office6 = new DeanOffice("教务办公室");
office7 = new AdminOffice("行政办公室"); office7 = new AdminOffice("行政办公室");
office8 = new DeanOffice("教务办公室"); office8 = new DeanOffice("教务办公室");
@ -40,9 +39,22 @@ int main()
head->add(office2); head->add(office2);
head->add(sichuanBranch); head->add(sichuanBranch);
head->operation(); head->operation();
system("pause"); system("pause");
delete head;
delete sichuanBranch;
delete cdBranch;
delete myBranch;
delete office1;
delete office2;
delete office3;
delete office4;
delete office5;
delete office6;
delete office7;
delete office8;
return 0; return 0;
} }

View File

@ -3,14 +3,14 @@
int main() int main()
{ {
printf("\nJungle的第一个手机:\n"); printf("\nJungle's first phone\n");
Component *c; Component *c;
Component *com_Shell; Component *com_Shell;
c = new Phone(); c = new Phone();
com_Shell = new DecoratorShell(c); com_Shell = new DecoratorShell(c);
com_Shell->operation(); com_Shell->operation();
printf("\nJungle的第二个手机:\n"); printf("\nJungle's second phone'\n");
Component *c2; Component *c2;
Component *com_Shell2; Component *com_Shell2;
c2 = new Phone(); c2 = new Phone();
@ -19,7 +19,7 @@ int main()
com_Sticker = new DecoratorSticker(com_Shell2); com_Sticker = new DecoratorSticker(com_Shell2);
com_Sticker->operation(); com_Sticker->operation();
printf("\nJungle的第三个手机:\n"); printf("\nJungle's third phone'\n");
Component *c3; Component *c3;
Component *com_Shell3; Component *com_Shell3;
c3 = new Phone(); c3 = new Phone();
@ -32,6 +32,15 @@ int main()
printf("\n\n"); printf("\n\n");
delete c;
delete com_Shell;
delete c2;
delete com_Shell2;
delete com_Sticker;
delete c3;
delete com_Sticker2;
delete com_Rope;
system("pause"); system("pause");
return 0; return 0;
} }

View File

@ -7,7 +7,7 @@ int main()
facade->powerOn(); facade->powerOn();
printf("\n\n"); printf("\n\n");
delete facade;
system("pause"); system("pause");
return 0; return 0;
} }

View File

@ -30,6 +30,12 @@ int main()
printf("\n\n"); printf("\n\n");
delete factory;
delete device1;
delete device2;
delete device3;
delete device4;
system("pause"); system("pause");
return 0; return 0;
} }

View File

@ -9,6 +9,8 @@ int main()
printf("\n\n"); printf("\n\n");
delete subject;
system("pause"); system("pause");
return 0; return 0;
} }

View File

@ -28,6 +28,16 @@ int main()
zuzhang->handleRequest(bill4); zuzhang->handleRequest(bill4);
printf("\n\n"); printf("\n\n");
delete zuzhang;
delete bingge;
delete chunzong;
delete laoban;
delete bill1;
delete bill2;
delete bill3;
delete bill4;
system("pause"); system("pause");
return 0; return 0;
} }