Recent

Author Topic: Heaptrace - positive false ?!  (Read 5986 times)

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: Heaptrace - positive false ?!
« Reply #15 on: March 05, 2019, 08:42:36 pm »
In both cases, after the dec-ref, str is a dangling pointer.
If everything worked so badly, it would really be a problem :). FPC work fine.
Code: Pascal  [Select][+][-]
  1. {$MODE OBJFPC}
  2. {$APPTYPE CONSOLE}
  3. {$LONGSTRINGS ON}
  4.  
  5. function Test(const S: string): string;
  6. begin
  7.   Writeln('Begin of function');
  8.   Writeln('S ref count is ', StringRefCount(S), ', Result ref count is ', StringRefCount(Result));
  9.   Writeln('Result := S;');
  10.   Result := S;
  11.   Writeln('S ref count is ', StringRefCount(S), ', Result ref count is ', StringRefCount(Result));
  12.   Writeln('UniqueString(Result);');
  13.   UniqueString(Result);
  14.   Writeln('S ref count is ', StringRefCount(S), ', Result ref count is ', StringRefCount(Result));
  15. end;
  16.  
  17. var
  18.   S: string;
  19. begin
  20.   S := 'Some data';
  21.   UniqueString(S); // const refcount is -1, break it
  22.   S := Test(S);
  23.   S := '';
  24.   S := Test(S);
  25.   Readln;
  26. end.

af0815

  • Hero Member
  • *****
  • Posts: 1291
Re: Heaptrace - positive false ?!
« Reply #16 on: March 06, 2019, 06:54:13 am »
In that case probably look further down in the list.
If you leak some object, that often leaks other data.
You are right, i worked on the list BOTTOM UP and found a leak in my factory, after close this leak, it works as expected and don't claim the 'positive false'.

So i have learned, heaptrace can go out of sync and it is better to attack an leak on a higher level in program.

And your discussion about reference couted variables and working give me a deeper understanding of the complexity of managed objects.
« Last Edit: March 06, 2019, 06:55:45 am by af0815 »
regards
Andreas

 

TinyPortal © 2005-2018