Solved

Memory Leaks

Posted on 1998-06-10
3
209 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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

728 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