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?

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


Please Help Members By Posting Answers For Below Questions

Why do we use polymorphism?

1129


Why do we need oop?

1273


What is the difference between a constructor and a destructor?

1340


What is stream in oop?

1358


to find out the minimum of two integer number of two different classes using friend function

2184


What makes a language oop?

1127


What is overloading and its types?

1245


What is object in oops?

1123


What is class in oop with example?

1158


What is a class oop?

1057


Write a program to reverse a string using recursive function?

2408


Who invented oop?

1193


write a code for this:trailer recordId contains a value other than 99, then the file must error with the reason ‘Invalid RECORD_ID’(User Defined Exception).

2199


hi all..i want to know oops concepts clearly can any1 explain??

2175


Is this job good for future? can do this job post grduate student?

2220