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 |
write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.
Why is oop useful?
What is function overloading and operator overloading?
If a=5, b=6, c=7, b+=a%c*2. What is the final value of b?
Should you protect the global data in threads? Why or why not?
Is this job good for future? can do this job post grduate student?
What do we mean by a hidden argument in C++?
What is the difference between a mixin and inheritance?
What is encapsulation?
Why do we use class in oops?
Why is abstraction needed?
Which type does string inherit from?