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 |
what is the technical or oop name of object?
What is polymorphism? Explain with an example.
INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?
what isthe difference between c structure and c++ class
Define a class to represent a bank account. Include the following members: Data Members: Name of the Depositor Account Number Type of Account Balance amount in the account Member Functions: To assign the initial values. To deposit an account. To withdraw an amount after checking the balance. Write a C++ main program to display account number, name and balance.
what is opps?why it is use in programming language?
WAP to generate 2n+1 lines of the following pattern on the computer screen:
Which method cannot be overridden?
how to find no of instances of an object in .NET?
what is the drawback of classical methods in oops?
Round up a Decimal number in c++.. example Note = 3.5 is as 4 3.3 is as 3
3 Answers Accenture, Cognizant, IBM,
Which is the only operator in C++ which can be overloaded but NOT inherited?