INTERVIEW QUESTIONS
C++
C++ BASICS
DETAILS
Question: what is memory leaking in c++ ?
Answer: When a class uses dynamically allocated memory internally , all sorts of problems arises.If not properly used or handled, they can lead to memory leaks & corrupts Data Structures.<br><br>Amemory leak is the situation that occurs when dynamically allocated memory is lost to the program.<br><br>char * p;<br><br>p= new char[10000];<br><br>.....<br><br>p= new char[5000];<br><br>Initially, 10000 bytes are dynamicallyallocated & the the address of those bytes is stored in p. later 5000 bytes are dyanmically allocated & the address is stored in p. However, the original 10000 bytes 've not been returned to the system using delete [] opertor . <br><br>Memory leak actually depends on the nature of the program. <br>
|
Question:
what is memory leaking in c++ ?
Answer:
When a class uses dynamically allocated memory internally , all sorts of problems arises.If not properly used or handled, they can lead to memory leaks & corrupts Data Structures.<br><br>Amemory leak is the situation that occurs when dynamically allocated memory is lost to the program.<br><br>char * p;<br><br>p= new char[10000];<br><br>.....<br><br>p= new char[5000];<br><br>Initially, 10000 bytes are dynamicallyallocated & the the address of those bytes is stored in p. later 5000 bytes are dyanmically allocated & the address is stored in p. However, the original 10000 bytes 've not been returned to the system using delete [] opertor . <br><br>Memory leak actually depends on the nature of the program. <br> Source: CoolInterview.com
Memory leaks generally occur due to inefficient usage of new operator.<br><br>When memory is dynamically allocated using new, the memory is assigned in the heap storage area of the program. This memory will not be deleted on its own since it is not dependent on the scope of the defined object as in the case of those objects that are created on the stack. <br><br>to delete such memory we have to call the destructor using delete operator.<br><br>As a result, it is advisable to match a new with a proper delete. Source: CoolInterview.com
Answered by: Akshay | Date:
| Contact Akshay
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|