Lazarus
Free Pascal => Unix => Topic started by: McKay1717 on May 29, 2017, 08:42:26 am
-
Hello,
I've some memory leak in my app so i've run valgrind to found the problem.
Valgrind give this output: https://paste.ubuntu.com/24700111/
I can read a greats number of problems with fcl-json and that problem to be point to cmem.
Have you any idea to solve this problem?
Thank's in advence.
-
Those more look like non-freed form resources/components, not json related? Btw, source code would be much easier to examine than excessive amount of errors
-
Indeed, i think i have do some mistake with the graphic component, what's the best way to close and free a graphical object ?
-
As a general rule, if you create a component with an owner (putting it on a form covers this) it's owner is responsible to free it but if you create a component without owner in code then you are responsible. You need to call it's free procedure. This is for component derivatives. Other objects like stringlist, bitmap etc. always needs to be freed manually. Best practice like below
var
bmp : TBitmap;
begin
bmp:=TBitmap.Create;
try
// Do something with bmp
finally
bmp.free;
end;
end;
-
That's is strange because i never create graphical object explicitly.
There is my code :
https://paste.debian.net/hidden/7460d837/ <- The Update Thread
https://paste.debian.net/hidden/214db026/ <- The Model
https://paste.debian.net/hidden/a43e12df/ <- The TForm
Thank's you for your help
-
Hi McKay1717,
The leak is caused by the GetJSON function. I mean the function is not leaking, however you must free jData in the end.
regards,
GetMem
-
i've add jData.Free at the end of my function but that's haven't any effect
-
It does not have to be graphical object. I took a glance of your code and could not see that you are freeing most objects like TFPObjectList instances. If you dont free these lists you create memory leaks both for theirselves and for their contents. Keep in mind, for every object you create you need to have destruction (by calling free) somewhere. Most probably in an overriden destructor (Destroy) in TLaserUpdateThread. Plus, notice that you need to free what GetJSON returns. It creates new JsonData and you're responsible to free it. Last note, thread destruction is more tricky if you want to wait them to finish and read their results but you need to free them too somehow.
-
All TFPObjectList as a Free. TFPObjectList who wasn't free in thread are free in the "Model" and all of TFPObjectList who was'nt Free in "Model" was free in controller. Finally I think, I can be wrong.
-
Hi, local Pointers used in the procedures like this:
procedure TLaser.Update;
var
p: Pointer; <--- This one
tmp: TFPObjectList;
begin
(..)
for p in tmp.List do
begin
PointList.Add(TPointStruct(p).clone);
end;
(...)
I think aren¡t freed,
Can be this the problem?
/BlueIcaro
-
I've finally found the problem. I've disable cmem and the memory usage will be stable.
Thanks you everyone for your help
(You can find the difference of memory usage in the following graph http://imgur.com/a/7iKMU)