Memory leaks in Tokyo 10.2.3 for linux and RO 9.4.109.1375

Evgeny,
Wich object is the owner? If theres two strong references one of this must be declared as weak. If both are strong reference then the refcount will never reach 0 and the memory will never be disposed!

Can you please test that? Im fighting with this problem for a week and this is a signal of clear problems at the hour or release memory.

Best regards.

AFAIK setting nil only decrease refcount and will not release memory if recount is different than 0. Setting will not help in this situation.

Will check that. Good point.
BTW, must not be better do that:

dw.DisposeOf;
dw := nil;

before next use of dw in the same scope?

What about this? Were are the two reference stored?

I will try to release manually and see if that fixed the problem.

in your case, owner is soJsonData, that holds FObject (private variable of TROJSONValue):

constructor TROJSONValue.Create(aType: TROJSONDataType);
begin
  inherited Create(nil);
  FObject := nil;
  case aType of
    jdtObject: FObject := TROJSONObject.Create;
    jdtArray: FObject := TROJSONArray.Create;
  end;
..
end;

if I make FObject as weak variable, FObject will be destroyed after constructor is finished and before you can get access to it via soJsonData.AsObject.

you can try to replace FreeAndNil with DisposeOf in TROJSONValue.Clear, but I think, it will not improve situation.

it won’t work at all because table.DynamicWhere is private object that is created in TDADataTable.Create so at second call, after disposiing this object you will get reference to freed object

the same as before - this is reference to TROJSONValue.FObject

Do you mean DisposeOf and nil?

But then you can confirm is a memory leak in the actual code or dont?

I will try differents scenarios anyway, but will be better if the library solve that problem by self or you can suggest a better use of the library to avoid that inconvience?

as I said, I don’t think that replacing FreeAndNil with DisposeOf will change anything.

btw, have you detected what objects are leaked in your program? Are these TROJSONValue objects?

I cant find a way to find that. I only know have several servers running on linux and that leaks memory every day.

I try leakcheck but the report at program close reports everything, even indy servers…

Any suggestions will be welcomed.

you can try to isolate code that causes memory leak.
for example copy/paste some code into new app and perform execution of that snippet a lot of time in loop and see if memory will be leaked.

btw, Are you using the latest UniDAC?
some their components had memory leaks: https://forums.devart.com/viewtopic.php?t=37182

But, the only why to see if memory is leaked is on the OS… :frowning:

Yes, is the latest release. They claim was solved.

Best regards