Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What is memory leak and memory corruption?



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

Post New Answer

More OOPS Interview Questions

advantage and disadvantage in c++>>oops and what are the questions ask for interview in c++>>oops. could you tell me or reply me

0 Answers  


explain dynamic binding by drowing

2 Answers   Cognizant,


Why multiple inheritance is not allowed?

0 Answers  


What is the difference between pass by value,pass by pointer,pass by reference in the catch block in the exception handling in c++

1 Answers   TCS,


Which method cannot be overridden?

0 Answers  


Can we override main method?

0 Answers  


why we call c++ is object oriented lanaguage

7 Answers   HCL,


What polymorphism means?

0 Answers  


Difference between over loading and over ridding?

12 Answers   CTS, Patni, Softvision Solution,


What is the default size allocated for array in the statement if size not specified " int a[] "

4 Answers   CTS,


write a progra in c++ using class & object to find out wheather a given no. is prim or not.

2 Answers  


What is the use of unnamed namespaces in OOPS? The only advantage I know is that they dont need the scope resolution operator while accessing them. I want to know some other advantages of unnamed namespaces...

2 Answers  


Categories