InterviewUp is actively seeking partnerships. Inquire at business@interviewup.com

Question & Additional Information
 
what is memory leaking in c++ ?
Add to My IQ
 

 | 
Inappropriate
Answer Title
Answer
Memory leak is - dynamically allocating memory and forgeting to free it. In C++, using a new operator to allocate a chunk of memory, and forgetting to delete it. There are several reasons this could occur. Some of them are,
1. Allocate a chunk of memory and assign the starting address to a pointer variable, and later, reassing another address to the same pointer without freeing its original address
2. Allocate memory for an array and not using proper delete method (delete[]) to free the memory
3. Unhandled exceptions - allocating memory and deleting it at the end of the program, but the program abnormally terminates (crashes) before the delete code line is executed.

Some of the ways of avoiding memory leaks within a class object are
1. Allocate all dynamic memory required for the class in the constructor, and delete it in the distructor
2. Use TRY/CATCH blocks around all statements where there is a possiblity of a crash
3. Override new operator for your class and Track memory allocations and pointers. Override delete operator and untrack the deleted/freed memory. In the destructor, check to see if there are any tracked memory locations (not freed) and free them up.
But beyond all these, it's still a good programming style that avoids memory leaks, because beyond objects, there is a program where you instantiate and run these objects. If you are allocating memory dynamically in the parent program, then carefully make sure you delete those chunks at all exit points (or centralize your exit point).
Question Tag Title
Tags
Question Asked At Title
Asked At
None
Question Job Title
Job Titles


Check out our newest job listings!

Post a Job! $49 for 60 days



Your Name:
Add your comment text
 
Related Questions
Related Questions
Flag this interview question as inappropriate Inappropriate
See Answer
classes declared within another class are called inner or nested classes
Create Date
:
Thursday, October 16, 2008
Tags
:
Asked At
:
Job Positions
:
None
Click here to improve the Interview Question, Answer and other fields.
Comments (0) :
Goto add your comment on the Question 
Flag this interview question as inappropriate Inappropriate
See Answer
you use function ptr when you want to call multiple functions using the ptr in a loop.
like have an array of funtion ptrs, loop through the array and execute the functions.
Create Date
:
Monday, January 21, 2008
Tags
:
Asked At
:
None
Job Positions
:
None
Click here to improve the Interview Question, Answer and other fields.
Comments (0) :
Goto add your comment on the Question 
Flag this interview question as inappropriate Inappropriate
See Answer

structures can be passed by reference.

they can be returned as pointers.

Create Date
:
Saturday, March 15, 2008
Asked At
:
None
Job Positions
:
Click here to improve the Interview Question, Answer and other fields.
Comments (0) :
Goto add your comment on the Question 
Flag this interview question as inappropriate Inappropriate
See Answer
pseudo code is the code written when converting the algorithm/ flow chart to actual code.
So it is in between the compiled code and flow chart. It is something that is not compiled but can be on
a notepad.
Create Date
:
Saturday, March 15, 2008
Tags
:
Asked At
:
None
Job Positions
:
Click here to improve the Interview Question, Answer and other fields.
Comments (0) :
Goto add your comment on the Question 
Flag this interview question as inappropriate Inappropriate
See Answer
Methods are for objects functions are regular routines
Create Date
:
Thursday, October 16, 2008
Tags
:
Asked At
:
None
Job Positions
:
None
Click here to improve the Interview Question, Answer and other fields.
Comments (0) :
Goto add your comment on the Question 
Flag this interview question as inappropriate Inappropriate
See Answer
Test s for prime or not?


#include<stdio.h>
void main(void)
{
           int no,rem,cnt;
        Printf("enter No");
        scanf("%d",&no);
        cnt=2;
        while(cnt<=no)
       {

              rem=no % cnt;
              if (rem==0)
              {
              printf("No is not prime");
              exit(0);
              }
              cnt++;
        }
          printf("No is Prime");
}



Create Date
:
Thursday, October 16, 2008
Tags
:
Asked At
:
None
Job Positions
:
None
Click here to improve the Interview Question, Answer and other fields.
Comments (0) :
Goto add your comment on the Question 
 
• More Related Questions: 
Suggestions & Comments




Share Your Interview Questions
Ask Interview Questions
View Unanswered Questions

















Advertise on this site