Article View: borland.public.cppbuilder.nativeapi
Article #2517Re: Memory Leak - TForm or TStringGrid or DynamicArray
From: Ed Mulroy
Date: Fri, 09 Feb 2007 16:40
Date: Fri, 09 Feb 2007 16:40
36 lines
2622 bytes
2622 bytes
> That one is best replaced by std::vector<char> Foo(26). IFF vector<char> can easily do what is needed. Both new/new[] and delete/delete[] have their uses. The uses just are not nearly as common as a new programmer might think (interesting thought - how about a new term "new programmer" as a pun in that the new programmer frequently programs with "new"). FWIW: In normal programs I use new/new[] and delete/delete[] frequently but they are almost exclusively found in constructors and destructors. In small (one-source-file main/WinMain and but a few functions 'quicky' programs) I usually don't use RAII at all and both new/new[] and delete/delete[] are used with impunity. In those cases things are so simple that there is little chance of missing a delete/delete[] by mistake or by exception. . Ed > Alan Bellingham wrote in message > news:0scos2d8fs92eis2eo0a7j91shnaaedbrd@4ax.com... > >>> ...I've said this before, and I'll say it again - if I see a delete >>> in user code, I consider it a warning sign that the code is >>> probably unsafe... >> >> std::auto_ptr<char> Foo(new char[26]); >> >>As the old saying goes, "all full generalizations are wrong, >>including this one" <g> > > Well, I didn't add the 'new considered unsafe' too, did I *grin* > > That one is best replaced by std::vector<char> Foo(26).
Technical Details
Message-ID:
<45cca5a5$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.media.kyoto-u.ac.jp!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<45c7810f@newsgroups.borland.com> <45c7dc8d$1@newsgroups.borland.com> <45c89ec6@newsgroups.borland.com> <45ca4546$1@newsgroups.borland.com> <0sqks2t4c90epuc62bv635h36cqeat0ujd@4ax.com> <45cb3451$1@newsgroups.borland.com> <ptems2p2k2rquqdiao805ik2fhg6jl9n9a@4ax.com> <45cbc696$1@newsgroups.borland.com> <0scos2d8fs92eis2eo0a7j91shnaaedbrd@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,191a7d21d69bde32 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Ed Mulroy" <dont_email_me@bitbuc.ket> Newsgroups: borland.public.cppbuilder.nativeapi References: <45c7810f@newsgroups.borland.com> <45c7dc8d$1@newsgroups.borland.com> <45c89ec6@newsgroups.borland.com> <45ca4546$1@newsgroups.borland.com> <0sqks2t4c90epuc62bv635h36cqeat0ujd@4ax.com> <45cb3451$1@newsgroups.borland.com> <ptems2p2k2rquqdiao805ik2fhg6jl9n9a@4ax.com> <45cbc696$1@newsgroups.borland.com> <0scos2d8fs92eis2eo0a7j91shnaaedbrd@4ax.com> Subject: Re: Memory Leak - TForm or TStringGrid or DynamicArray Date: Fri, 9 Feb 2007 11:40:28 -0500 Lines: 38 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 66.57.117.102 Message-ID: <45cca5a5$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1171039653 66.57.117.102 (9 Feb 2007 08:47:33 -0800) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.media.kyoto-u.ac.jp!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail