Solved

Memory Leaks

Posted on 1998-06-10
3
206 Views
Last Modified: 2010-04-01
The following question I am asking as beginner.
Does it insure there will no memory leaks if write "delete <object>" for every corresponding "new <object>" ?
If Yes, how ?
If No, Why ? and What more steps do I need to take.
Thanx
0
Comment
Question by:shivag
  • 2
3 Comments
 
LVL 6

Expert Comment

by:WxW
ID: 1165560
Yes

In general , any pointer you initialize with new must be deleted with delete . If you initialize an array , you must use delete[] to remove it . You do not need to remove variables that are not pointers like e.g. char Str[10000]; This is removed automatically when goes out of scope
0
 

Expert Comment

by:Samir040498
ID: 1165561
Yes

When you call delete on an object its destructor is called giving you the chance to destroy you object correctly. So as long as you have a new and a corresponding delete for it in the correct places you won't have to worry.

Hey by the way there is a good FAQ on C++ (in case your interested) at http://www.cerfnet.com/~mpcline/c++-faq-lite/


0
 

Accepted Solution

by:
Samir040498 earned 20 total points
ID: 1165562
Yes

When you call delete on an object its destructor is called giving you the chance to destroy you object correctly. So as long as you have a new and a corresponding delete for it in the correct places you won't have to worry.

Hey by the way there is a good FAQ on C++ (in case your interested) at http://www.cerfnet.com/~mpcline/c++-faq-lite/ 

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question