What are ways to avoid memory leaks?- A memory leak is the effect of running out of memory. - A memory leak is what happens when you forget to free a block of memory allocated with the new operator or when you make it impossible to so. - The measures you can take are : i. Delete before reallocating a memory ii. Be sure you have a pointer to each dynamic variable so that you do not lose a location that you need to free. iii. Avoid these combinations : - malloc() - delete and new - free() - new - delete [] and new [] - delete.When are memory leaks important? What are the easiest ways to avoid memory leak?Memory Leaks :- Memory leaks take up more memory space and causes slow calculation. - Ensure that the loops or conditional statements are executed completely to prevent memory leak occurrence. - The best and easiest way to avoid memory leaks is to make changes at the time of writing programs. - The cause for this is, a properly planned program can avoid memory leaks. In addition to it, make a code snippet can be made simple, small which executes fast..
|