What is memory leak and memory corruption?
Answer / shyamal bose
Memory leaks happens for the memory allocated on Heap(ex A
*temp = new A()) . memory allocated by us on stack (int a)
is released automatically when the function returns or
module goes out of scope.
But memory allocated on heap will not be freed
automatically, we need to release it manually.
ex:
func()
{
A *a = new A(); //on heap
int b; // on stack
}
main()
{
func();
}
Now in above example when func is called memory for "a" is
created on HEAP by using NEW, but it is not freed by using
DELETE, hence is memory leak. On the other hand "b" is
created on STACK & freed automatically. so correct
implementation is:
func()
{
A *a = new A(); //on heap
int b; // on stack
delete a; //deleting memory on heap
}
main()
{
func();
}
| Is This Answer Correct ? | 7 Yes | 0 No |
How can i write a code in c# to take a number from the user and then find all the prime numbers till the number entered by the user.
How do you define social class?
Write a program to reverse a string using recursive function?
design class for linked list and include constructor,destructor,insert option. node of form struct node { int data; struct node &ptr; }
1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321
what is difference between objects and function
What are oops functions?
Name a typical usage of polymorphism
program in c++ that can either 2 integers or 2 floating point numbers and output the smallest number
why the argument is passed by reference to a copy constructor?example?
Which type does string inherit from?
What is a null tree?