Re: new without delete: what will happen

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



In find these days that I rarely write "new" for arrays. CString, CByteArray, and other
array classes using SetSize are good substitutes (my client base doesn't use or want
std::, which in many cases would be even nicer).

Mostly I use 'new' for class objects that have a lifetime longer than the scope of a
function, such as values added to the ItemData of a CLIstBox or CComboBox or the LPARAM of
a CListCtrl. Then I write the DeleteItem code immediately.

I remember when memory leaks were a problem; as Doug points out, with good programming
practice, they hardly ever exist.
joe

On Tue, 28 Jun 2005 16:05:27 -0500, "Doug Harrison [MVP]" <dsh@xxxxxxxx> wrote:

>On Tue, 28 Jun 2005 12:46:20 -0500, Doug Harrison [MVP] wrote:
>
>> Hmmm, I use new regularly, but I hardly ever write delete, and yet I can't
>> remember the last time I leaked memory. How can this be? I use smart
>> pointers and classes such as std::vector extensively.
>
>To clarify, I use new mainly for scalars that I store in smart pointers,
>while std::vector takes the place of array new.

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Overloading OPERATOR(+): my usage causing memory leaks.
    ... I apply it to array arguments. ... what in the code could be causing these memory leaks? ... end interface assignment ... elemental subroutine my_destroy ...
    (comp.lang.fortran)
  • Re: Solving overwrites/leaks
    ... it *does* have buffer underrun and overrun checking. ... declare an array of length 100 and write to the 101st position, ... > I've looked at the ENTREK software, and it does look like a good solution ... >> checking for memory leaks, tracking where they occurred, etc. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: DEBUG_NEW in template class?
    ... I would move all the 'delete's to the wrapper class ... That is, remove all deletes from code, loop the array in the ... > I'm debugging memory leaks in an inherited application. ...
    (microsoft.public.vc.mfc)
  • Re: Array of object from varius subclasses
    ... Marco ... >>into an array. ... one can use the assignment operator to change an ... will indeed cause memory leaks. ...
    (comp.lang.cpp)
  • Re: string to array
    ... Bob Barrows [MVP] wrote: ... Earlier responses had mentioned using InStr, and since abcd kept asking, I ... also provides the position of that character in the string. ... how can I convert this string into array so that I get the values ...
    (microsoft.public.scripting.vbscript)