<!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><TITLE>Message</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<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 
namespaceuri="urn:schemas-microsoft-com:office:smarttags" 
name="PersonName"></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 dir=ltr align=left><SPAN class=854112603-04052007><FONT face=Arial 
color=#0000ff size=2>That code's safe from a memory POV, but I wouldn't have 
coded it like that personally, because to me, the intentions aren't clear.&nbsp; 
I believe that the fact that you had to go and look at the implementation 
supports my suggestion of trying to clarify intentions.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=854112603-04052007><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=854112603-04052007><FONT face=Arial 
color=#0000ff size=2>I haven't used TFindFile (so unsure of all the code), but 
personally I would have coded&nbsp;TFindFile so that you would use it along the 
lines of:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=854112603-04052007><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=854112603-04052007><FONT face=Arial 
color=#0000ff size=2>tf := TFindFile.Create;</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=854112603-04052007><FONT face=Arial 
color=#0000ff size=2>try</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=854112603-04052007><FONT face=Arial 
color=#0000ff size=2>&nbsp; if tf.SearchForFiles 
then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
// SearchForFiles does a search and returns a boolean</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=854112603-04052007><FONT face=Arial 
color=#0000ff size=2>&nbsp;&nbsp;&nbsp; Memo1.Lines.Assign(tf.FoundFiles);&nbsp; 
// where FoundFiles is a TStringList _property_ of TFindFile</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=854112603-04052007><FONT face=Arial 
color=#0000ff size=2>finally</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=854112603-04052007><FONT face=Arial 
color=#0000ff size=2>&nbsp; tf.Free;</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=854112603-04052007><FONT face=Arial 
color=#0000ff size=2>end;</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN 
class=854112603-04052007>Neven's free to disagree.&nbsp; I'm not telling people 
what to do, I'm just telling you what I find easiest to 
follow.</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><SPAN class=854112603-04052007><FONT face=Arial color=#0000ff 
size=2>C.</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT><BR></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
</DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT size=2><FONT 
face=Tahoma><B>From:</B> delphi-bounces@delphi.org.nz 
[mailto:delphi-bounces@delphi.org.nz] <B>On Behalf Of </B>John Bird<BR><SPAN 
class=854112603-04052007><FONT face=Arial 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT size=2><SPAN 
class=321173002-04052007><FONT face=Arial color=#0000ff>I have seen an exact 
similar case in one of the few external components I use - 
TFindFile</FONT></SPAN></FONT></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><SPAN class=321173002-04052007><SPAN class=854112603-04052007><FONT 
face=Arial color=#0000ff size=2>&nbsp;</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=321173002-04052007>&nbsp;</SPAN><FONT size=2><FONT 
face=Tahoma>-----Original Message-----<BR><B>From:</B> 
delphi-bounces@delphi.org.nz [mailto:delphi-bounces@delphi.org.nz] <B>On Behalf 
Of </B>Xander (GMail)</FONT></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">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>
  <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><SPAN 
  style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">From:</SPAN></FONT></B><FONT 
  face=Tahoma><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><SPAN 
  style="FONT-WEIGHT: bold"><SPAN class=854112603-04052007><FONT face=Arial 
  color=#0000ff>&nbsp;</FONT></SPAN></SPAN></SPAN></FONT></P>
  <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><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial"><SPAN 
  class=854112603-04052007>&nbsp;</SPAN></SPAN></DIV>
  <DIV><FONT face=Tahoma><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></SPAN></FONT><FONT face=Tahoma><SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma"><SPAN 
  class=854112603-04052007><FONT face=Arial 
  color=#0000ff>&nbsp;</FONT></SPAN></SPAN></FONT></DIV>
  <DIV><FONT face=Tahoma><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></DIV>
  <BLOCKQUOTE style="MARGIN-TOP: 5pt; MARGIN-BOTTOM: 5pt; MARGIN-RIGHT: 0cm">
    <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 
    :-)</SPAN></FONT></P></DIV></BLOCKQUOTE></DIV></BLOCKQUOTE></BODY></HTML>