Solved

Memory Leaks

Posted on 1998-06-10
3
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

749 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