Solved

Memory Leaks

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

829 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