🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1490

std::auto_ptr<> Memory Leak?

#1490
From: Dan
Date: Mon, 13 Aug 2007 19:11
32 lines
2019 bytes
I have the following code:

std::auto_ptr<TStringList> Times(new TStringList());
for (int i=0;i<100; i++)
{
   String StartTime = Now();
   std::auto_ptr<TADOQuery> Query(new TADOQuery(this));
   Query->Connection = Database;
   Query->SQL->Text = "Select * from Customers where Cust_Id = 
"+(String)i; //yes, each customer has the same amount of information
   Query->Active = true;
   String StopTime = Now();
   Times->Add(StartTime+"\t"+EndTime);
}
ShowMessage(Times->Text);

I'm confused why the execution time grows each time through the loop as 
shown in the message at the end.  Of course, I could move the creation 
of the object 'Query' outside of the loop; however, that defeats the 
function I wanted; in my main code I have a similar loop that creates an 
object (say bob) that then creates that query (without a loop) and it 
appears as though as the number of times I create the 'bob' object the 
slower the system gets and the above code snip demonstrates the same effect.

Ideas?


The other reason I posted the above here for help is because if I watch 
the task manager, the amount of memory listed on the processes tab for 
this process grows while in the loop, which I wouldn't expect.

Thoughts?
Technical Details
Message-ID: <46c0acfc$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,a638a12efe982a3a,start
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Mon, 13 Aug 2007 14:11:57 -0500
From: Dan <Dan@do.not.spam>
User-Agent: Thunderbird 1.5.0.12 (Windows/20070509)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: std::auto_ptr<> Memory Leak?
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 216.174.165.174
Message-ID: <46c0acfc$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1187032316 216.174.165.174 (13 Aug 2007 12:11:56 -0700)
Lines: 32
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail