Memory leaks are bugs in C++ applications that can cause performance problems with your applicatio
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 <stdlib.h>
#include <crtdbg.h>
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: <Sheldon > 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<stdlib.h>
#include<crtdbg.h>
#include<string>
void memLeak()
{
int *p = newint;
char * string1 = newchar[20];
char * string2 = newchar[25];
strcpy(string1, "Sheldon");
string2=string1;
delete p;
}
int main(intargc, char* argv[])
{
memLeak();
_CrtDumpMemoryLeaks();
return 0;
}
9 years ago
Purchase the answer to view it

- answer_-to-week_5_help.zip