[fpc-pascal] possible json parser memory leak

Frank Church vfclists at gmail.com
Sun Dec 18 21:27:54 CET 2011


On 18 December 2011 17:34, silvioprog <silvioprog at gmail.com> wrote:

> 2011/12/18 ik <idokan at gmail.com>:
> > Hello,
> >
> > I'm using FPC 2.6 (rc) x86_64 on Linux with JSONParser.
> >
> > I've written the following code:
>
> Use:
>
> var
>  parser: TJSONParser;
>  json_data: TJSONData;
>  json_file: TFileStream;
> begin
>  json_file := TFileStream.Create('test.json', fmOpenRead);
>  parser := TJSONParser.Create(json_file);
>  json_data := parser.Parse;
>  WriteLn(json_data.AsJSON);
>  json_data.Free;
>  json_file.Free;
>  parser.Free;
> end;
>
> Thx.
>
>
I am getting some issues with memory leaks and want to see if this topic
sheds some light on the issue.
>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.

>writeln('JSON: ', parser.Parse.AsJSON);

Does this represent a common case where using AsXXX creates an object?

 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?

It looks to me that lot of leaky code is created which looks right unless
you know more about the functions used create objects..

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.


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



> --
> Silvio Clécio
> ===============================================
> Blog - <silvioprog.com.br>
> Twitter - <twitter.com/silvioprog>
> Facebook - <facebook.com/silvioclecio>
> LazSolutions - <code.google.com/p/lazsolutions>
> Lazarus-BR - <groups.google.com.br/group/lazarus-br?hl=pt-BR>
> ===============================================
>    * Conheça nosso canal IRC sobre Lazarus: #lazarus-br *
> ===============================================
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



-- 
Frank Church

=======================
http://devblog.brahmancreations.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20111218/ac20dfb9/attachment.html>


More information about the fpc-pascal mailing list