Menu

Memory Leak when creating S7Object (S7Client & Delphi)

Cliff
2015-01-28
2015-01-29
  • Cliff

    Cliff - 2015-01-28

    Hi,
    I'm trying to establish a connection t a PLC using Delphi XE5 and the wrappers,
    Function of Snap7 works fine so far.

    My problem:
    Snap7 generates memory- leaks when creating the object.

    My Code (Snippet):

    s7Client:=TS7Client.Create;
    try
          // Do something
    finally
      s7Client.Free;
    end;
    

    MadExcept reports an unreleased thread- handle for every call of this snippet.
    It looks like something is not released properly.
    I have tried to debug this and it looks like the s7- object itself is released properly.

    Can someone help?

     
  • Davide Nardella

    Davide Nardella - 2015-01-28

    Hi,
    I program in Delphi but I don't use MadExcept.
    With FastMM no issues are reported but maybe it works on different level.

    Can I make the same tests also with the personal (non commercial) edition ?
    Can you send me a very small complete program (XE5) that I can test showing also the setting that are you using for MadExcept ? You can use davenardella at live dot it.

    The client thread is always destroyed into the object destructor.

    Regards
    Davide

     
  • Cliff

    Cliff - 2015-01-28

    Hi,
    thanks for the quick response.
    I have generated a test project with just a button on it.
    Only code is:

    procedure TFrmSnap7Test.btn1Click(Sender: TObject);
    var s7Client: TS7Client;
    begin
    s7Client:=TS7Client.Create;
    try
    Sleep(200)
    finally
    s7Client.Free
    end;
    end;

    I have removed MadExcept and other stuff.
    When you watch the application with the process explorer (Sysinternals) you can see the handles growing with each click...

    Regards
    Andreas

     
  • Davide Nardella

    Davide Nardella - 2015-01-29

    Hi Andreas,
    maybe too time spent around unix programming made me forget that Windows needs an additional handle destruction (CloseHandle) :(

    Please, can you test it ? (ProcessExplorer now reports the handles releasing).

    Thanks
    Davide

     
  • Cliff

    Cliff - 2015-01-29

    Hi Davide,

    looks much better now!
    No more leaks reported by Processexplorer and MadExcept.
    (Just ran my test- program in a loop from 1 to 100 ;-) )

    Regards
    Andreas

     
  • Davide Nardella

    Davide Nardella - 2015-01-29

    Many thanks for the support Andreas ;)
    I will prepare the update fix asap.

     

Log in to post a comment.