<div dir="ltr">On Sun, Dec 18, 2011 at 22:27, Frank Church <span dir="ltr"><<a href="mailto:vfclists@gmail.com">vfclists@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><br><div class="gmail_quote"><div class="im">On 18 December 2011 17:34, silvioprog <span dir="ltr"><<a href="mailto:silvioprog@gmail.com" target="_blank">silvioprog@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2011/12/18 ik <<a href="mailto:idokan@gmail.com" target="_blank">idokan@gmail.com</a>>:<br>
<div>> Hello,<br>
><br>
> I'm using FPC 2.6 (rc) x86_64 on Linux with JSONParser.<br>
><br>
> I've written the following code:<br>
<br>
</div>Use:<br>
<br>
var<br>
parser: TJSONParser;<br>
json_data: TJSONData;<br>
json_file: TFileStream;<br>
begin<br>
json_file := TFileStream.Create('test.json', fmOpenRead);<br>
parser := TJSONParser.Create(json_file);<br>
json_data := parser.Parse;<br>
WriteLn(json_data.AsJSON);<br>
json_data.Free;<br>
json_file.Free;<br>
parser.Free;<br>
end;<br>
<br>
Thx.<br>
<br></blockquote></div><div><br>I am getting some issues with memory leaks and want to see if this topic sheds some light on the issue.<br>From the original posters question it appears that parse.Parse.AsJSON create an object which needed to be free although there was no explicit Txxx.Create in the code.<br>
<br>>writeln('JSON: ', parser.Parse.AsJSON);<br>
<br>Does this represent a common case where using AsXXX creates an object?<br></div></div></blockquote><div><br>Nop, AsJSON is a function with string. Parse is function that return a class. The thing is, that the function is designed to not to manage memory. It can not actually. If you wanted a memory manager it should have been property and not a function.<br>
<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_quote"><div><br> Is there some way of telling whether some types of functions create objects which need to be freed even although they do not offer handles which can be used to free them?<br>
</div></div></blockquote><div><br>I think most of them, if not all. Because you can not manage memory that you do not own. When you return a created object and send it as a result. Then it can not follow it anymore.<br> </div>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_quote"><div>
<br>It looks to me that lot of leaky code is created which looks right unless you know more about the functions used create objects..<br></div></div></blockquote><div><br>The memory leak was in my code, due to usage of the library, not in the library. But only after I saw the answer, I noticed it was a function and not a property. <br>
</div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_quote"><div><br>I am using the XML libraries and beginning to suspect that lots of this kind of problem are lurking within the code I am writing.<br>
</div></div></blockquote><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_quote"><div>
<br><br>PS. Does every 'Call trace xxx' represent an object created that wasn't freed? I asked about this in another thread but haven't gotten a reply yet<br><br> </div><div class="im"><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
--<br>
Silvio Clécio<br>
===============================================<br>
Blog - <<a href="http://silvioprog.com.br" target="_blank">silvioprog.com.br</a>><br>
Twitter - <<a href="http://twitter.com/silvioprog" target="_blank">twitter.com/silvioprog</a>><br>
Facebook - <<a href="http://facebook.com/silvioclecio" target="_blank">facebook.com/silvioclecio</a>><br>
LazSolutions - <<a href="http://code.google.com/p/lazsolutions" target="_blank">code.google.com/p/lazsolutions</a>><br>
Lazarus-BR - <<a href="http://groups.google.com.br/group/lazarus-br?hl=pt-BR" target="_blank">groups.google.com.br/group/lazarus-br?hl=pt-BR</a>><br>
===============================================<br>
* Conheça nosso canal IRC sobre Lazarus: #lazarus-br *<br>
===============================================<br>
_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br>
</blockquote></div></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><br>-- <br>Frank Church<br><br>=======================<br><a href="http://devblog.brahmancreations.com" target="_blank">http://devblog.brahmancreations.com</a><br>
</font></span><br>_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br></blockquote></div><br></div>