Hi guys its been a while i just wanna ask if you have any idea why this code leaking. The below code is just a sample representation on how it works in one of the parts of my actual program that causes leaks.
Thanks in advanceCode:#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <iostream> #include <string> #ifdef _DEBUG #define MEMLEAK_CHECK_ON #endif #ifdef MEMLEAK_CHECK_ON #define CRTDBG_MAP_ALLOC #include <stdlib.h> #include <crtdbg.h> #endif using namespace std; struct sample { string *name; int xpos; int ypos; }; sample *a = NULL; sample *b = NULL; void init(); int _tmain(int argc, _TCHAR* argv[]) { init(); a->name[0].clear(); a->name[1].clear(); delete a; #ifdef MEMLEAK_CHECK_ON _CrtDumpMemoryLeaks(); #endif return 0; } void init() { a = new sample(); a->name = new string[2]; a->name[0] ="Sample1"; a->name[1] = "Sample2"; a->xpos = 12; a->ypos = 13; size_t nLength = a->name->length(); }




Reply With Quote