Answer Posted / 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 |
Post New Answer View All Answers
Is react oop?
What is encapsulation in ict?
What is polymorphism explain its types?
What is Difference Between Inheritance and creating object and getting data? means Class A extends B{ B.getMethod();} (OR) Class A{ b obj=new B(); obj.getMethod(); }
Write a program to compute for numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format: Each line contains a student's first name, then one space, then ten quiz scores all on one line. The quiz scores are in whole number and are separated by one space. Your program will take it input from this file and sends it output to a second file. The data in the output file will be exactly the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student's ten quiz scores. Use at least one function that has file streams as all or some of its arguments.
What are the two different types of polymorphism?
What is the difference between inheritance and polymorphism?
What is the importance of oop?
What does enum stand for?
Explain the concepts involved in Object Oriented programming.
What is the highest level of cohesion?
Why is static class not inherited?
What is encapsulation oop?
any one please tell me the purpose of operator overloading
What is the point of oop?