Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Database/DataSnap    [ Add a report in this area ]  
Report #:  78696   Status: Closed
Memory Leak in TDSServerConnection for in-process connection
Project:  Delphi Build #:  14.0.3513.24210
Version:    14.0 Submitted By:   Chee Yang Chau
Report Type:  Basic functionality failure Date Reported:  10/15/2009 8:02:54 PM
Severity:    Serious / Highly visible problem Last Updated: 4/20/2013 6:24:45 AM
Platform:    All platforms Internal Tracking #:   13034
Resolution: Fixed (Resolution Comments) Resolved in Build: : XE3
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 17
Description
TDSServerConnection is instantiated when perform in-process datasnap connection.

Method DerivedOpen get invoked while start the connection:

procedure TDSServerConnection.DerivedOpen;
begin
  FConnectMessage.ConnectProperties := FConnectionProperties;
  TMonitor.Enter(self);
  try
  begin
    if FConHandler = nil then
    begin
      FNextHandler := TDSVoidConnectionHandler.Create(FDbxContext);
      FConHandler := TDSServerConnectionHandler.Create(FDbxContext, FNextHandler, nil);
      FConHandler.ServerConnection := self;
      FConHandler.Server := TDSServer.FindCustomServer(FConnectionProperties[TDBXPropertyNames.DriverName]);
      FConHandler.DbxConnect(FConnectMessage);
    end;
  end
  finally
    TMonitor.Exit(self);
  end

end;

However, FConHandler never free while TDSServerConnection instance get close or destroy.
Steps to Reproduce:
Run the following code will show memory leaks:

var Q: TSQLConnection;
    D: TDSServer;
begin
  ReportMemoryLeaksOnShutdown := True

  Q := TSQLConnection.Create(nil);
  D := TDSServer.Create(nil);
  try
    D.Start;
    Q.DriverName := 'DSServer';
    Q.LoginPrompt := False;
    Q.Open;
    Q.Close;
    D.Stop;
  finally
    D.Free;
    Q.Free;
  end;
end;
Workarounds
Refer to http://chee-yang.blogspot.com/2009/10/datasnap-in-process-server-method.html
Attachment
None
Comments

Walter Frederico Bauchspiess at 4/2/2012 7:11:35 AM -
Still happens on HE2

Walter Frederico Bauchspiess at 4/2/2012 7:12:03 AM -
I mean: Still happens on XE2.

Michael Leaver at 10/1/2012 2:06:48 AM -
Appears to be fixed in XE3.

Tomohiro Takahashi at 10/1/2012 7:36:49 AM -
Thanks for the information. I will check the internal status of this report.

Server Response from: ETNACODE01