{"id":217650,"date":"2018-09-15T23:00:52","date_gmt":"2018-09-15T23:00:52","guid":{"rendered":"http:\/\/localhost\/wordpress\/index.php\/2018\/09\/15\/gsp-215-week-5-homework-memory-leaks\/"},"modified":"2018-10-24T08:56:57","modified_gmt":"2018-10-24T08:56:57","slug":"gsp-215-week-5-homework-memory-leaks","status":"publish","type":"post","link":"https:\/\/www.benedictsol.com\/blogs\/gsp-215-week-5-homework-memory-leaks\/","title":{"rendered":"GSP 215 Week 5 Homework memory Leaks"},"content":{"rendered":"<p>Week 5 Homework&#8221;\ufffdMemory Leaks\t\u00a0\tMemory leaks are bugs in C++ applications that can cause performance problems with your application or even causing it to crash. A memory leak is the result of failing to deallocate memory that was previously allocated. In C++ the commands\t#define _CRTDBG_MAP_ALLOC\t#include <stdlib.h>\t#include <crtdbg.h>\twill enable the debug heap functions. After enabling the debug heap functions, place a call to _crtDumpMemoryLeaks() before an application exit point.\u00a0\tGiven the following code, run this code in debug mode. The memory leak report will appear in the Output Window with the debug option. It should look something like this.\t\u00a0\tThe output will look like the following.\t\u00a0\tDetected memory leaks!\tDumping objects ->\t{142} normal block at 0x0079A948, 25 bytes long.\t\u00a0Data: < \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0> CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD\u00a0\t{141} normal block at 0x0079A8F8, 20 bytes long.\t\u00a0Data: <Sheldon \u00a0 \u00a0 \u00a0 \u00a0 > 53 68 65 6C 64 6F 6E 00 CD CD CD CD CD CD CD CD\u00a0\tObject dump complete.\tThe information displayed is: the memory allocation number (142), block type (normal), the hexadecimal memory location (0x0079A948), and the size of the block (25 bytes long).\u00a0\tRewrite the code to remove the memory leaks, and submit the completed code with a screenshot of the output window with no memory leaks detected.\t\u00a0\t#define _CRTDBG_MAP_ALLOC\t#include <stdlib.h>\t#include <crtdbg.h>\t#include <string>\t\u00a0\t\u00a0\tvoid memLeak()\t{\tint *p = new int;\tchar * string1 = new char[20];\tchar * string2 = new char[25];\tstrcpy(string1, &#8220;Sheldon&#8221;);\t\u00a0\tstring2=string1;\tdelete p;\t}\t\u00a0\tint main(int argc, char* argv[])\t{\t\u00a0 \u00a0 memLeak();\t_CrtDumpMemoryLeaks();\t\u00a0\treturn 0; \t}\t\u00a0\t\u00a0\tC++ code with no memory leaks:\t\u00a0\t\u00a0\tScreenshot:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Week 5 Homework&#8221;\ufffdMemory Leaks \u00a0 Memory leaks are bugs in C++ applications that can cause performance problems with your application or even causing it to crash. A memory leak is the result of failing to deallocate memory that was previously <a href=\"https:\/\/www.benedictsol.com\/blogs\/gsp-215-week-5-homework-memory-leaks\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-217650","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/217650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/comments?post=217650"}],"version-history":[{"count":0,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/217650\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/media?parent=217650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/categories?post=217650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/tags?post=217650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}