Solved

Memory Leaks

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now