Resolution! I look extensively at Todd's recommendation that pointer variables not be used in ThreadVars, but with literally hundreds in my app I couldn't see a logical or actual problem.
I'm using a TTimer to dispatch scheduled tasks. Originally I was spawning a new TThread, but had a few problems, so did a quick and dirty change to TTimer. My code assumed it's work was running in a thread, so created and destroyed some pointer type ThreadVars (stringlists, components etc). But of course TTimers run in the app's main thread. TTimer sets up variables fires up particular job ok. I have my TTimer keep track of the task, but only by a simple Tag mechanism. This is meant to check for dead or hung tasks. After 500 clicks it resets itself, cleans up threadvars and fires another job. Meantime long running database update job suddenly finds it's threadvars gone, and poof! It falls over. Problem solved, but complex because of threading, and I suppose because of how much I'm trying to do at the same time, without being a multi-threading expert. Thanks for those who helped with suggestions. David McNeill McPond eCommerce Software [EMAIL PROTECTED] Buchanan Road Franklin New Zealand Phone 09 292 7212 -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Todd Martin Sent: Thursday, 11 September 2003 4:22 p.m. To: Multiple recipients of list delphi Subject: Re: [DUG]: TStringList or Memory error. Hi David At what point do you free the list? At the end of Execute() or in an OnTerminate() event handler? Todd. ----- Original Message ----- From: "David McNeill" <[EMAIL PROTECTED]> To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]> Sent: Thursday, September 11, 2003 4:01 PM Subject: RE: [DUG]: TStringList or Memory error. > Indy HTTP creates a new thread for each web request. > > At the start of that new thread I create the stringlist, then call the > processing procedure that use it. > > What gets me is how it can work for 700 cycles (ie the code has to be > correct), then tip over. > > It must be a more dynamic memory allocation related issue, I just have > no idea how to debug that. > > > > > > > > David McNeill > McPond eCommerce Software > [EMAIL PROTECTED] > Buchanan Road > Franklin > New Zealand > Phone 09 292 7212 > > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > Behalf Of Phil Middlemiss > Sent: Thursday, 11 September 2003 1:42 p.m. > To: Multiple recipients of list delphi > Subject: Re: [DUG]: TStringList or Memory error. > > If the stringlist belongs to the thread then you shouldn't need a > critical > section. But if you are accessing the StringList in an event from the > Indy > components when data arrives then you may still need a critical section > - I > can't remember if the Indy components use the same or a different thread > for > each event notification. > > Phil. > ----- Original Message ----- > From: "David McNeill" <[EMAIL PROTECTED]> > To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]> > Sent: Thursday, September 11, 2003 1:30 PM > Subject: RE: [DUG]: TStringList or Memory error. > > > > Thanks for the pointers... > > > > 1) Are you using interfaces? If so, check that the referenced object > > hasn't > > been relased. > > > > .. No interfaces > > > > > > 2) Have you got your code that references the stringlist wrapped up in > a > > critical section? > > > > .. Shouldn't need to because it's threadvar - the thread can write to > > the string list any time it feels like it, it has it's own instance of > > the stringlist. > > Is my assumption correct? > > > > > > 3) Are you trying to access an item in the list that doesn't exist > (eg, > > MyList[4] when MyList only contains 4 items - remember that > TStringList > > is 0 > > based)? > > > > .. Only using .add Generally I then use .text then .clear , so no, > > not an indexing issue. > > > > > > > > > > > > > > > > These are probably all obvious ones you have already checked, but you > > didn't > > say what you had checked or not. > > > > Phil. > > ----- Original Message ----- > > From: "David McNeill" <[EMAIL PROTECTED]> > > To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]> > > Sent: Thursday, September 11, 2003 11:56 AM > > Subject: [DUG]: TStringList or Memory error. > > > > > > > This is a nasty one I can't get to the bottom of, so any clues or > tips > > > would be appreciated. > > > > > > Fundamental problem: Access Violation on accessing a stringlist. > > > > > > Situation: Database update process iterates 700+ times, doing the > same > > > thing, before tipping over. > > > > > > It's like the tstringlist "disappears" for some unknown reason. > > > > > > I use the same method in thousands of other lines, and never fails. > > > > > > Breaks on two servers at the customers place, but not on my dev > > server. > > > > > > > > > Multi-threaded tray app, using Indy http server. > > > > > > > > > Snips: > > > > > > > > > Main.pas > > > threadvar > > > tlResult:TStringlist; > > > > > > Main.pas > > > Procedure TimerExecute; > > > Tlresult:=tstringlist.create; > > > > > > DoDatabaseProcessing; > > > > > > > > > Database.pas > > > Procedure DoDatabaseProcessing; > > > While not database.eof do begin > > > .. hundreds of lines > > > tlresult.add('Ok: Processed item '+IntToStr(RecordNo)); // access > > > violation > > > end; > > > > > > > > > > > > > > > I tried descending tstringlist and putting in a log on > > BeforeDestruction > > > , but it does not appear the stringlist is explicitly being > destroyed. > > > > > > It is more like something else is clobbering it's memory, and it is > > > "disappearing" at some point. > > > > > > Any help appreciated. > > > > > > > > > David McNeill > > > McPond eCommerce Software > > > [EMAIL PROTECTED] > > > Buchanan Road > > > Franklin > > > New Zealand > > > Phone 09 292 7212 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > -- > > - > > > New Zealand Delphi Users group - Delphi List - > > [EMAIL PROTECTED] > > > Website: http://www.delphi.org.nz > > > To UnSub, send email to: [EMAIL PROTECTED] > > > with body of "unsubscribe delphi" > > > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ > > > > > > > > > > ------------------------------------------------------------------------ > > --- > > New Zealand Delphi Users group - Delphi List - > [EMAIL PROTECTED] > > Website: http://www.delphi.org.nz > > To UnSub, send email to: [EMAIL PROTECTED] > > with body of "unsubscribe delphi" > > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ > > > > > > > > > ------------------------------------------------------------------------ > -- > - > > New Zealand Delphi Users group - Delphi List - > [EMAIL PROTECTED] > > Website: http://www.delphi.org.nz > > To UnSub, send email to: [EMAIL PROTECTED] > > with body of "unsubscribe delphi" > > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ > > > > > ------------------------------------------------------------------------ > --- > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > Website: http://www.delphi.org.nz > To UnSub, send email to: [EMAIL PROTECTED] > with body of "unsubscribe delphi" > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ > > > > ------------------------------------------------------------------------ -- - > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > Website: http://www.delphi.org.nz > To UnSub, send email to: [EMAIL PROTECTED] > with body of "unsubscribe delphi" > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ ------------------------------------------------------------------------ --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
