Article View: borland.public.cppbuilder.nativeapi
Article #17344Re: Ternary operator memory leak
From: Mark Guerrieri
Date: Fri, 04 Apr 2003 05:24
Date: Fri, 04 Apr 2003 05:24
45 lines
2802 bytes
2802 bytes
> How about setting the condition so that it is always false
> and see if you still have a leak? Seems like if the term
> that should be evaluated if the condition is true, got
> evaluated every time through the loop, then you would
> have an allocation that's discarded(leak.) I dunno' why
> this would happen though.
Ok, I did some more testing. Here is a simple way to reproduce the problem.
Create a project with a single form, drop a TTimer on it, set the interval
to 100 and add this code to the OnTimer event:
for(int i=0; i<100; i++)
{
AnsiString cTest = (true) ? AnsiString("Pass").Trim() :
AnsiString("Fail").Trim();
}
Run it and watch your memory bleed away. Here are all the possible
permutations:
AnsiString cTest = (true) ? AnsiString("Pass").Trim() :
AnsiString("Fail").Trim(); = LEAK
AnsiString cTest = (false) ? AnsiString("Pass").Trim() :
AnsiString("Fail").Trim(); = LEAK
AnsiString cTest = (true) ? AnsiString("Pass") : AnsiString("Fail"); = NO
LEAK
AnsiString cTest = (false) ? AnsiString("Pass") : AnsiString("Fail"); = NO
LEAK
AnsiString cTest = (true) ? AnsiString("Pass").Trim() : AnsiString("Fail");
= NO LEAK
AnsiString cTest = (false) ? AnsiString("Pass").Trim() : AnsiString("Fail");
= LEAK
AnsiString cTest = (true) ? AnsiString("Pass") : AnsiString("Fail").Trim();
= NO LEAK
AnsiString cTest = (false) ? AnsiString("Pass") : AnsiString("Fail").Trim();
= LEAK
So it seems that whenever the evaluated expression does a Trim(), memory is
leaked. Why would this be? Someone tell me I'm crazy and they can also
reproduce this so I can post it to QualityCentral.
Mark
Technical Details
Message-ID:
<3e8d169d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!newshosting.com!news-xfer2.atl.newshosting.com!ken-transit.news.telstra.net!news.telstra.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3e8bf300$1@newsgroups.borland.com> <qkep8vg83uauivbohirnld8akmmttav577@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,e689c7bb2171dc9a X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-04-03 21:29:27 PST Reply-To: "Mark Guerrieri" <mguerrieri@cmsgrp.com> From: "Mark Guerrieri" <mguerrieri@cmsgrp.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3e8bf300$1@newsgroups.borland.com> <qkep8vg83uauivbohirnld8akmmttav577@4ax.com> Subject: Re: Ternary operator memory leak Date: Fri, 4 Apr 2003 00:24:44 -0500 Lines: 47 Organization: Creative Marketing Strategies X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 66.200.143.50 Message-ID: <3e8d169d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1049433757 66.200.143.50 (3 Apr 2003 21:22:37 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!newshosting.com!news-xfer2.atl.newshosting.com!ken-transit.news.telstra.net!news.telstra.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail