I'm using sgcWebsockets 2023.4.0 with Lazarus/FPC, Windows 11 Pro
With a skeleton setup I have a memory leak.
Am I just missing something simple here?
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
Classes, sysutils,
sgcWebSocket,
sgcWebSocket_Classes,
sgcWebSocket_Types;
type
{ TServer }
TServer = class
strict private
fServer: TsgcWebSocketServer;
procedure ProcessIncomingMessage(pConnection: TsgcWSConnection; const pText: string);
procedure DoConnection(pConnection: TsgcWSConnection);
procedure DoDisconnect(pConnection: TsgcWSConnection; somenum: integer);
public
procedure Start;
end;
{ TServer }
procedure TServer.ProcessIncomingMessage(pConnection: TsgcWSConnection; const pText: string);
begin
Writeln('Raw incoming data');
Writeln(pText);
end;
procedure TServer.DoConnection(pConnection: TsgcWSConnection);
begin
Writeln('client connected...');
end;
procedure TServer.DoDisconnect(pConnection: TsgcWSConnection; somenum: integer);
begin
writeln('disconnecting client');
end;
procedure TServer.Start;
begin
Writeln('Starting websocket server');
fServer := TsgcWebSocketServer.Create(nil);
try
fServer.Port := 8090;
fServer.NotifyEvents := neNoSync;
fServer.OnMessage := @ProcessIncomingMessage;
fServer.OnConnect := @DoConnection;
fServer.OnDisconnect := @DoDisconnect;
fServer.Active := true;
while fServer.Active do begin
Sleep(10);
end;
finally
fServer.Free;
end;
end;
var
oServer: TServer;
begin
oServer := TServer.Create;
try
oServer.Start;
finally
oServer.Free;
end;
end.