GSP 215 Week 5 Homework memory Leaks

Week 5 Homework”�Memory Leaks   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 allocated. In C++ the commands #define _CRTDBG_MAP_ALLOC #include #include will enable the debug heap functions. After enabling the debug heap functions, place a call to _crtDumpMemoryLeaks() before an application exit point.  Given 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.   The output will look like the following.   Detected memory leaks! Dumping objects -> {142} normal block at 0x0079A948, 25 bytes long.  Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD  {141} normal block at 0x0079A8F8, 20 bytes long.  Data: 53 68 65 6C 64 6F 6E 00 CD CD CD CD CD CD CD CD  Object dump complete. The 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).  Rewrite the code to remove the memory leaks, and submit the completed code with a screenshot of the output window with no memory leaks detected.   #define _CRTDBG_MAP_ALLOC #include #include #include     void memLeak() { int *p = new int; char * string1 = new char[20]; char * string2 = new char[25]; strcpy(string1, “Sheldon”);   string2=string1; delete p; }   int main(int argc, char* argv[]) {     memLeak(); _CrtDumpMemoryLeaks();   return 0; }     C++ code with no memory leaks:     Screenshot:

Previous answers to this question


This is a preview of an assignment submitted on our website by a student. If you need help with this question or any assignment help, click on the order button below and get started. We guarantee authentic, quality, 100% plagiarism free work or your money back.

order uk best essays Get The Answer
Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *