Re: new without delete: what will happen
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Tue, 28 Jun 2005 22:15:19 -0400
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
.
- References:
- new without delete: what will happen
- From: bbg
- Re: new without delete: what will happen
- From: Jonathan Wood
- Re: new without delete: what will happen
- From: bbg
- Re: new without delete: what will happen
- From: Jonathan Wood
- Re: new without delete: what will happen
- From: bbg
- Re: new without delete: what will happen
- From: darsant@xxxxxxxxx
- Re: new without delete: what will happen
- From: Doug Harrison [MVP]
- Re: new without delete: what will happen
- From: Doug Harrison [MVP]
- new without delete: what will happen
- Prev by Date: Re: CTime
- Next by Date: Re: How do I get CFormView to move while busy processing.
- Previous by thread: Re: new without delete: what will happen
- Next by thread: Re: new without delete: what will happen
- Index(es):
Relevant Pages
|