A memory leak can be avoided by making sure that whatever memory has been dynamically allocated will be cleared after the use of the same. for example int main() { char *myCharData[20]; for (int nLoop =0;nLoop < 20; ++nLoop) { myCharData[nLoop ] = new char[256]; strcpy(myCharData[nLoop],"SABITH"); ....... } ......................... /*Some manipulations here using myCharData*/ /*Now here we have to clear the data. The place can vary according to ur program. This being a simple program,u can clear at the end*/ for(int nLoop =0;nLoop < 20; ++nLoop) { delete[] myCharData[nLoop ]; } return 0;
Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.
Copyright ©2003-2009 CoolInterview.com, All Rights Reserved. Privacy Policy | Terms and Conditions Page URL: http://www.coolinterview.com/interview/6078/default.asp?cachecommand=bypass