Welcome, Guest
Username: Password: Remember me
General discussions, feature requests for CodeTyphon Project and discussions that don't fit in any of the other specific CodeTyphon forum categories.
  • Page:
  • 1
  • 2

TOPIC:

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8804

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
Sir, the heaptrc.trc is empty
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8805

  • Dinko
  • Dinko's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 91
  • Thank you received: 5
I managed to create false heaptrc report with 0 unfreed blocks. Checkout HeaptraceConfig.png configuration. Try and recompile and you will get 0 unfreed.
But, if you uncomment heaptrc after cmem statement in program unit, and uncheck Use heaptrc unit then you will get correct report.

According to picture you send I can tell that you did not press and key to finish program. When you press and key command prompt will appear (or black window will disappear) and heaptrc will be created.

One more proof that something is wrong is TaskManager. I increase loop to 1000000 just to force program to run much longer, so I can look task manager. You can see that CT570 consumes lot of memory and CT540 almost nothing for the same source.

Sorry for badgering, but this is really important form me, and others. I think 99% of applications are somehow database connected.
Maybe someone other can confirm this behavior of CT570.. In attachment you can find latest source.

Regards, Dinko

Please Log in or Create an account to join the conversation.

Last edit: by Dinko. Reason: Change picture :-)

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8809

  • Dinko
  • Dinko's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 91
  • Thank you received: 5
I think I found leak.
In sqldb.pp there is function GetStatementInfo. Line 1445 is
SetString(s, PhraseP, CurrentP-PhraseP);
I think line should be
// SetString(s, PhraseP, CurrentP-PhraseP);
// Correct line
// This shoulfd fix the problem but missbehaviour is deep inside fpc
s := Copy(PhraseP, 1, CurrentP-PhraseP);

How this worked before (because it is not changed accross the versions) I dont know. Probably they changed SetString in fpc source (or some other string handling function). I saw that change much in c:\codetyphon\fpcsrc\rtl\inc\ directory

In attachement you can find isolated function (it was not hard to pull out this function and call it), so you can debug for yourself.

C:\codetyphon\CodeOcean\Database\samples\xbin\TestMemoryLeak.exe
Heap dump by heaptrc unit
1482 memory blocks allocated : 58361/59072
1467 memory blocks freed : 58058/58720
15 unfreed memory blocks : 303
True heap size : 294912 (128 used in System startup)
True free heap : 293280
Should be : 293472
Call trace for block $01811D78 size 15
Block content: 000001000100000002000000617300 -

$0040345F GETSTATEMENTINFO, line 283 of TestMemoryLeak.lpr
$00403DBD main, line 578 of TestMemoryLeak.lpr
Call trace for block $018327F8 size 44
Block content: 00000100010000001F0000002827323031362D30312D30312030313A30313A30312720617320746578742900 -
1 1-01 01 01:
$0040345F GETSTATEMENTINFO, line 283 of TestMemoryLeak.lpr
$00403DBD main, line 578 of TestMemoryLeak.lpr
Call trace for block $01811D18 size 17
Block content: 0000010001000000040000006361737400 -

Regards, Dinko
Attachments:

Please Log in or Create an account to join the conversation.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8810

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
Sir
we make test with your fix
is this heaptrc.trc OK ?
C:\codetyphon\CodeOcean\Database\samples\xbin\TestMemoryLeak.exe 
Heap dump by heaptrc unit
2897 memory blocks allocated : 249989/253688
2897 memory blocks freed     : 249989/253688
0 unfreed memory blocks : 0
True heap size : 163840 (192 used in System startup)
True free heap : 163648

if it's ok,
please, post the fix and to FreePascal Mantis
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

Last edit: by Sternas Stefanos.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8812

  • Dinko
  • Dinko's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 91
  • Thank you received: 5
If you used new version of TestMemoryLeak application then you should see something like
I left memory leak on purpose.

C:\codetyphon\CodeOcean\Database\samples\xbin\TestMemoryLeak.exe
Heap dump by heaptrc unit
1482 memory blocks allocated : 58361/59072
1467 memory blocks freed : 58058/58720
15 unfreed memory blocks : 303
True heap size : 294912 (128 used in System startup)
True free heap : 293280
Should be : 293472
Call trace for block $001E1D28 size 15
Block content: 000001000100000002000000617300 -

$0040345F GETSTATEMENTINFO, line 283 of TestMemoryLeak.lpr
$00403DBD main, line 578 of TestMemoryLeak.lpr
Call trace for block $002027A8 size 44
Block content: 00000100010000001F0000002827323031362D30312D30312030313A30313A30312720617320746578742900 -


I think that we dont have the same fpc source. How we can check this:
For example maybe we can check c:\codetyphon\fpcsrc\rtl\inc\
dynarr.inc is last changed and it is from 26.12.2015 11:01, it is 12774 bytes.

I use Typhon win32 to build win32 application. Do you use Typhon Win32 or Typhon Win64?

Regards, Dinko

Please Log in or Create an account to join the conversation.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8813

  • Dinko
  • Dinko's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 91
  • Thank you received: 5
Problem is that this fix only fixes fcl-db but nothing else. If bug exists in SetString procedure then this affects lot of other non db related sources.
SetString is widely used all over fpc.

Regards, Dinko

Please Log in or Create an account to join the conversation.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8814

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
I am alone here and now, my programming team gone... for holidays.
From new year (2016), we will fix and this problem of FreePascal
Happy new year Sir
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

Last edit: by Sternas Stefanos.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8815

  • Dinko
  • Dinko's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 91
  • Thank you received: 5
OK. I'm going to rest till next year. In meantime I reproduced error with simple program without database.
SetString behaviour is changed. That is the problem
In attachement you can find simple memory leak test program. It is easy to understand.

Happy new year.

Regards, Dinko

Please Log in or Create an account to join the conversation.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8816

  • Dinko
  • Dinko's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 91
  • Thank you received: 5
Reported a bug in bugs.freepascal.org/view.php?id=29297

Regards, Dinko

Please Log in or Create an account to join the conversation.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8830

  • Dinko
  • Dinko's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 91
  • Thank you received: 5
FPC people claim that they can not reproduce problem with fpc from 2015-12-31 - rev. 32810.
bugs.freepascal.org/view.php?id=29297

Simple Memory Leak Program (I hope it helps).
Fresh install of CT560 on Windows 7 64 bit. CT560 is Win32.

program SimpleMemoryLeak;

{$mode objfpc}{$H+}

uses
cmem,
heaptrc, // Important - Uncheck / Project Options / Debugging / Use HeapTcr unit
lineinfo, // Important - Uncheck / Project Options / Debugging / Dispaly line numbers ....
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, Classes, SysUtils,
DateUtils;

procedure SimpleLeak;
var MyS: String;
MyPchar1: PChar;
MyString: String;
begin
MyString := 'TestString';
MyPChar1 := PChar(MyString);
SetString(MyS, MyPChar1, Length(MyString));
//MyS := ''; this line is needed for CT570 to avoid leak. It is not needed for CT540
SetString(MyS, MyPChar1, Length(MyString) - 5);
// MyS := Copy(MyS, 1, Length(InString) - 5);
end;

{$R *.res}

begin
if FileExists('.\heaptrc.trc') then DeleteFile('.\heaptrc.trc');
heaptrc.printfaultyblock := True;
heaptrc.printleakedblock := True;
heaptrc.quicktrace := True;
heaptrc.HaltOnNotReleased := True;
heaptrc.SetHeapTraceOutput('.\heaptrc.trc');

Writeln('');
Writeln('*********************************************');
Writeln('');

Writeln('SetString Leak');

SimpleLeak;


Writeln(' ');
Writeln('Finish, you can find the output data in file :');
Writeln('../xbin/heaptrc.trc');
Writeln('Hit any key to exit... After that check heaptrc.trc for leaks.');
Readln;
end.

HeapTrc Result is:


G:\temp\xbin\SimpleMemoryLeak.exe
Heap dump by heaptrc unit
263 memory blocks allocated : 8425/8936
262 memory blocks freed : 8402/8912
1 unfreed memory blocks : 23
True heap size : 196608 (96 used in System startup)
True free heap : 196416
Should be : 196424
Call trace for block $01767B18 size 23
Block content: 00000100010000000A00000054657374537472696E6700 -

Tes Str
$00402CC2
$00402DF0

Regards, Dinko
Attachments:

Please Log in or Create an account to join the conversation.

Last edit: by Dinko.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8831

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
Thanks Sir
we will test and report
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8844

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
Sir
I think we solve this problem
is this heaptrc.trc OK ?
C:\codetyphon\CodeOcean\aa_LabTests\samples\xbin\SimpleMemoryLeak.exe 
Heap dump by heaptrc unit
260 memory blocks allocated : 8478/9064
260 memory blocks freed     : 8478/9064
0 unfreed memory blocks : 0
True heap size : 425984 (128 used in System startup)
True free heap : 425856
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8847

  • Dinko
  • Dinko's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 91
  • Thank you received: 5
0 unfreed - this should be OK.
I hope you did not comment heaptrc unit in main program unit - if you do you will get 0 unfreed - like you should get, bit this is actually false report (this is also question to talk about).
So, what was the problem. Do you plan to put update for CT560 so I can test.

Regards, Dinko

Please Log in or Create an account to join the conversation.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8848

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
Yes, we will release Lab CT 5.70 revision 005620
but we want 2-3 days to Fix and Test some things
PilotLogic Architect and Core Programmer
The following user(s) said Thank You: Dinko

Please Log in or Create an account to join the conversation.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8861

  • Dinko
  • Dinko's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 91
  • Thank you received: 5
I updated CT560 to CT5620.
Memory Leak is gone. Thanks...

Now, one more request.
Is it possible for you to make CT560 package with all included fixes so I can download CT560 and avoid update to CT570 unofficial.
I think, that maybe, it will be good practice that current stable version have some link for service pack packages which needs to be applied to current version, or,
even better that current stable version have all fixes included.
Imagine that you have new user which download CT560 and CT560 is not stable enough but update exists. How can this new user know that he must update this release first before it try to use it.

Thanks, again for this memory leak fix. I will make some more tests which are important for me and if I found error I will report it.

Regards, Dinko
The following user(s) said Thank You: zeljko

Please Log in or Create an account to join the conversation.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8862

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
Sir
we can't change CT release procedure so simple
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8869

  • Dinko
  • Dinko's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 91
  • Thank you received: 5
May I suggest some approach. I don't know is it possible, but...

In CodeTyphon Update Manager you have two choices:
1. Latest Released Version (Stable)
2. LAB Development Version (Experimental)

Add third one:
3. Update From Local Drive (or local server)

This options assume that you have standard location for update files, and you put download link updated files somewhere on you web site.
The procedure goes like this.
- I download update files ans save it (somewhere on local disk or standard location)
- Go to Update Manager
- Chose 3rd option for update and chose directory location or just go to standard one.

This can be it or is it too complicated also ?


I have problems when I need to use some old version of CT because of some components (for example) which can not be updated to new version.
So far my only option is to install CT, install update, install components, install all cross build libraries which I need and then pack whole directory C:\Typhon and Documents and Settings user Roaming typhon32 and typhon64.
And this is only working solution for Windows. If I use Linux I need to do that for Linux..

See the point? Or maybe you have some other, better approach to this problem.

Regards, Dinko

Please Log in or Create an account to join the conversation.

CT560 MemoryLeak - ProjectExample 8 years 10 months ago #8870

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
Sir
please, you must understand and our internal problems and limitations.
From our "Release Model"
-The installation directory of CodeTyphon can't be change
-The update files are only available from Our Servers, with the use of CTC
-CodeTyphon IS Rolling Release
PilotLogic Architect and Core Programmer
The following user(s) said Thank You: Dinko

Please Log in or Create an account to join the conversation.

Last edit: by Sternas Stefanos.
  • Page:
  • 1
  • 2