ger@prisma.cv.ruu.nl (Ger Timmens) (08/12/90)
When I allocate temporary memory in a function, like this: 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 ? Thanks, +===========================================================+ | Ger Timmens, 3 Dimensional Computer Vision Research Group | + Academical Hospital Utrecht, Heidelberglaan 100 + + 3584 CX Utrecht, THE NETHERLANDS, e-mail: ger@cv.ruu.nl + | Tel.No.: +31-30-506711, Fax.No.: +31-30-513399 | +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+ | Delft, Universiry of Technology | + Faculty of Technical Mathematics and Informatics + | Section of Applied Analysis | +===========================================================+
880716a@aucs.uucp (Dave Astels) (08/13/90)
In article <ger.650468079@prisma> 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