Path: utzoo!attcan!uunet!cs.dal.ca!aucs!880716a From: 880716a@aucs.uucp (Dave Astels) Newsgroups: comp.lang.c++ Subject: Re: deleting allocated memory Message-ID: <1990Aug13.110859.18618@aucs.uucp> Date: 13 Aug 90 11:08:59 GMT References: Reply-To: 880716a@aucs.UUCP (Dave Astels) Distribution: comp.lang.c++ Organization: School of Computer Science, Acadia Univ., Nova Scotia Lines: 26 In article ger@prisma.cv.ruu.nl (Ger Timmens) writes: >When I allocate temporary memory in a function, like this: > > double padTempArray = new double [100]; Oops! You should have: double * padTempArray = new double [100]; ^ >do I have to delete this before I return from this function ? >I believe this is done automatically when the function goes out >of scope. If so, should I delete it manually or let the compiler >do the work ? As I understand it, anything allocated using `new' has to be explicitly deallocated (using `delete'). The compiler will insure that an object is deallocated on exit from the scope [that it was allocated in] in the case of a statically declared object. Eg: String x ("hi"); // will be deallocated implicitly String *x = new String ("hi"); // must be explicitly deallocated -- "I liked him better before he died" - McCoy, ST V =============================================================================== Dave Astels | Internet: 880716a@AcadiaU.CA PO Box 835, Wolfville, | Bitnet: 880716a@Acadia