<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:v = 
"urn:schemas-microsoft-com:vml" xmlns:o = 
"urn:schemas-microsoft-com:office:office" xmlns:w = 
"urn:schemas-microsoft-com:office:word" xmlns:st1 = 
"urn:schemas-microsoft-com:office:smarttags"><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>

<META content="MSHTML 6.00.6000.16414" name=GENERATOR><!--[if !mso]>
<STYLE>v\:* {
        BEHAVIOR: url(#default#VML)
}
o\:* {
        BEHAVIOR: url(#default#VML)
}
w\:* {
        BEHAVIOR: url(#default#VML)
}
.shape {
        BEHAVIOR: url(#default#VML)
}
</STYLE>
<![endif]--><o:SmartTagType name="PersonName" 
namespaceuri="urn:schemas-microsoft-com:office:smarttags"></o:SmartTagType><!--[if !mso]>
<STYLE>st1\:* {
        BEHAVIOR: url(#default#ieooui)
}
</STYLE>
<![endif]-->
<STYLE>@font-face {
        font-family: Tahoma;
}
@font-face {
        font-family: Verdana;
}
@page Section1 {size: 595.3pt 841.9pt; margin: 72.0pt 90.0pt 72.0pt 90.0pt; }
P.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"
}
LI.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"
}
DIV.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
        COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
        COLOR: blue; TEXT-DECORATION: underline
}
SPAN.EmailStyle17 {
        COLOR: navy; FONT-FAMILY: Verdana; mso-style-type: personal-reply
}
DIV.Section1 {
        page: Section1
}
</STYLE>
</HEAD>
<BODY lang=EN-US vLink=blue link=blue>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff size=2>I have 
seen an exact similar case in one of the few external components I use - 
TFindFile</FONT></SPAN></DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff size=2>which 
has code like:</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2>s:TStringlist is a private variable in the FindFiles 
unit,</FONT></SPAN></DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2>function TFindFile.SearchForFiles: 
TStringList;<BR>begin<BR>&nbsp; s.Clear;<BR>&nbsp; try<BR>&nbsp;&nbsp;&nbsp; 
FileSearch(Path);<BR>&nbsp; finally<BR>&nbsp;&nbsp;&nbsp; Result := s;<BR>&nbsp; 
end;<BR>end;<BR></FONT></DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff size=2>the 
only reference to&nbsp;s in the FileSearch function is</FONT></SPAN></DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2>&nbsp;&nbsp;&nbsp;&nbsp; s.Add(inPath + 
Rec.Name);<BR></FONT></SPAN></DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff size=2>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff size=2>The 
component also has:</FONT></SPAN></DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2>constructor TFindFile.Create(AOwner: TComponent);<BR>begin<BR>&nbsp; 
inherited Create(AOwner);<BR>&nbsp; Path := 
IncludeTrailingBackslash(GetCurrentDir); <BR>&nbsp; FileMask := '*.*';<BR>&nbsp; 
FileAttr := [ffaAnyFile];<BR>&nbsp; s := 
TStringList.Create;<BR>end;</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2>destructor TFindFile.Destroy;<BR>begin<BR>&nbsp; s.Free;<BR>&nbsp; 
inherited Destroy;<BR>end;<BR></FONT></SPAN></DIV></DIV></FONT></SPAN>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff size=2>I call 
it from my program with code like:</FONT></SPAN></DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff size=2>&nbsp; 
strlist:TStringList;</FONT></SPAN></DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2>and</DIV>
<DIV><BR></DIV></FONT></SPAN>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff size=2>&nbsp; 
strlist:=FindFile1.SearchforFiles;</FONT></SPAN></DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff size=2>That 
is I do no creating or freeing of the strlist myself - the component does all of 
the housework is my understanding.&nbsp; Thats one of the reasons I use it, as 
it encapsulates a few fiddly things like this.</FONT></SPAN></DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff size=2>Is 
this correct use or is this creating memory leaks?&nbsp; I found errors if I 
tried to create or free the strlist myself - and was advised that effectively 
the component was doing this and I didn't need to.</FONT></SPAN></DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=321173002-04052007><FONT face=Arial color=#0000ff size=2>[This 
is a utility I have for recursive folder searches of source files for a matching 
string displaying matches in a stringgrid - a sort of visual Grep - would be 
happy to share it if anyone can point out any errors or 
improvements]&nbsp;</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2>F<SPAN 
class=321173002-04052007>rom the Help</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
class=321173002-04052007></SPAN></FONT></FONT></FONT></SPAN>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN 
class=321173002-04052007>"TStringList.Clear:</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN 
class=321173002-04052007></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN 
class=321173002-04052007>Deletes all the strings from the 
list.</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN 
class=321173002-04052007>procedure Clear; override;</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN 
class=321173002-04052007>Description</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=321173002-04052007>Call 
clear to empty the list of strings. All references to associated objects are 
also removed. However, the objects themselves are not 
freed."</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN 
class=321173002-04052007></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN 
class=321173002-04052007></SPAN></FONT>&nbsp;</DIV>
<DIV class=Section1>
<P class=MsoAutoSig align=left>John<SPAN class=321173002-04052007><FONT 
face=Arial color=#0000ff size=2>&nbsp;</FONT></SPAN></P>
<P class=MsoAutoSig align=left><SPAN class=321173002-04052007>&nbsp;</SPAN><FONT 
face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> 
delphi-bounces@delphi.org.nz [mailto:delphi-bounces@delphi.org.nz] <B>On Behalf 
Of </B>Xander (GMail)<BR><B>Sent:</B> Friday, 4 May 2007 2:02 p.m.<BR><B>To:</B> 
'NZ Borland Developers Group - Delphi List'<BR><B>Subject:</B> RE: [DUG] Dumb 
Friday Question<BR><BR></P></FONT></DIV>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px">
  <DIV class=Section1>
  <P class=MsoNormal><FONT face=Verdana color=navy size=2><SPAN 
  style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Verdana">Jeremy,<o:p></o:p></SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Verdana color=navy size=2><SPAN 
  style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Verdana"><o:p>&nbsp;</o:p></SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Verdana color=navy size=2><SPAN 
  style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Verdana">If the function 
  returns a TStringList then it should be the responsibility of the caller of 
  that function to FREE the returned TStringList after it has finished using it. 
  You cannot free it inside the function.<o:p></o:p></SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Verdana color=navy size=2><SPAN 
  style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Verdana"><o:p>&nbsp;</o:p></SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Verdana color=navy size=2><SPAN 
  style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Verdana">Regards<o:p></o:p></SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Verdana color=navy size=2><SPAN 
  style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Verdana"><o:p>&nbsp;</o:p></SPAN></FONT></P>
  <DIV>
  <DIV class=MsoNormal style="TEXT-ALIGN: center" align=center><FONT 
  face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">
  <HR tabIndex=-1 align=center width="100%" SIZE=2>
  </SPAN></FONT></DIV>
  <P class=MsoNormal><B><FONT face=Tahoma size=2><SPAN 
  style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">From:</SPAN></FONT></B><FONT 
  face=Tahoma size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma"> 
  delphi-bounces@delphi.org.nz [mailto:delphi-bounces@delphi.org.nz] <B><SPAN 
  style="FONT-WEIGHT: bold">On Behalf Of </SPAN></B>Leigh Wanstead<BR><B><SPAN 
  style="FONT-WEIGHT: bold">Sent:</SPAN></B> Friday, May 04, 2007 1:55 
  PM<BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> vss@vss.co.nz; 
  <st1:PersonName w:st="on">NZ Borland Developers Group - Delphi 
  List</st1:PersonName><BR><B><SPAN 
  style="FONT-WEIGHT: bold">Subject:</SPAN></B> RE: [DUG] Dumb Friday 
  Question</SPAN></FONT><o:p></o:p></P></DIV>
  <P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN 
  style="FONT-SIZE: 12pt"><o:p>&nbsp;</o:p></SPAN></FONT></P>
  <DIV>
  <P class=MsoNormal><FONT face=Arial color=blue size=2><SPAN 
  style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">Hi 
  Jeremy,</SPAN></FONT><o:p></o:p></P></DIV>
  <DIV>
  <P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN 
  style="FONT-SIZE: 12pt">&nbsp;<o:p></o:p></SPAN></FONT></P></DIV>
  <DIV>
  <P class=MsoNormal><FONT face=Arial color=blue size=2><SPAN 
  style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">I think you need this 
  one <A 
  href="http://v.mahon.free.fr/pro/freeware/memcheck">http://v.mahon.free.fr/pro/freeware/memcheck</A></SPAN></FONT><o:p></o:p></P></DIV>
  <DIV>
  <P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN 
  style="FONT-SIZE: 12pt">&nbsp;<o:p></o:p></SPAN></FONT></P></DIV>
  <DIV>
  <P class=MsoNormal><FONT face=Arial color=blue size=2><SPAN 
  style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">;-)</SPAN></FONT><o:p></o:p></P></DIV>
  <DIV>
  <P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN 
  style="FONT-SIZE: 12pt">&nbsp;<o:p></o:p></SPAN></FONT></P></DIV>
  <DIV>
  <P class=MsoNormal><FONT face=Arial color=blue size=2><SPAN 
  style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">Regards</SPAN></FONT><o:p></o:p></P></DIV>
  <DIV>
  <P class=MsoNormal><FONT face=Arial color=blue size=2><SPAN 
  style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">Leigh</SPAN></FONT><o:p></o:p></P></DIV>
  <DIV>
  <P class=MsoNormal><FONT face=Arial color=blue size=2><SPAN 
  style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial"><A 
  href="http://www.smootharm.com">www.smootharm.com</A></SPAN></FONT><o:p></o:p></P></DIV>
  <BLOCKQUOTE style="MARGIN-TOP: 5pt; MARGIN-BOTTOM: 5pt; MARGIN-RIGHT: 0cm">
    <P class=MsoNormal style="MARGIN-BOTTOM: 12pt"><FONT face=Tahoma 
    size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">-----Original 
    Message-----<BR><B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> 
    delphi-bounces@delphi.org.nz [mailto:delphi-bounces@delphi.org.nz]<B><SPAN 
    style="FONT-WEIGHT: bold">On Behalf Of </SPAN></B>Jeremy Coulter<BR><B><SPAN 
    style="FONT-WEIGHT: bold">Sent:</SPAN></B> Friday, 4 May 2007 1:28 
    p.m.<BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> 
    delphi@delphi.org.nz<BR><B><SPAN 
    style="FONT-WEIGHT: bold">Subject:</SPAN></B> [DUG] Dumb Friday 
    Question</SPAN></FONT><o:p></o:p></P>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">Hi All. This is a question that 
    might be infulenced by some serious lack of sleep 
    :-)<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">&nbsp;<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">I have a funtion. Its return 
    result is a TStringlist.<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">In my code I&nbsp;create 
    a&nbsp;TStringlist then add my values to it, then pass this to the RESULT 
    varaible for the function.<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">&nbsp;<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">Now,&nbsp; this is prob. an 
    obvious answer than I&nbsp;prob. do actually know, but if I 
    got:-<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">&nbsp;<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">sResult := 
    TStringList.create;<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">sResult.add('blah');<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">Result:=sResult;<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">&nbsp;<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">Then if I free sResult, then I 
    loss the values I added, and the result is empty as you would 
    expect.<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">But the issue I have is, so if 
    I DONT free sResults, what happens to it? Surley it stays in memory,a dn I 
    would end up with a memory leack after repeaditive calls. Is that right? Or 
    is because the variable is function specific its free by default 
    etc?<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">Its a basic question I 
    know....but the more I thought about it the more uncertain I became....I 
    really need some sleep so that prob. the real probelm 
    :-)<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">&nbsp;<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">Jeremy<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">&nbsp;<o:p></o:p></SPAN></FONT></P></DIV>
    <DIV>
    <P class=MsoNormal><FONT face=Tahoma size=2><SPAN 
    style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">&nbsp;<o:p></o:p></SPAN></FONT></P></DIV></BLOCKQUOTE></DIV><BR><BR>__________ 
  NOD32 2238 (20070503) Information __________<BR><BR>This message was checked 
  by NOD32 antivirus system.<BR><A 
  href="http://www.eset.com">http://www.eset.com</A><BR></BLOCKQUOTE></BODY></HTML>