RTC Forums

Subscription => Support => Topic started by: thomh on May 29, 2014, 06:41:43 PM



Title: Memory leak on client app shutdown
Post by: thomh on May 29, 2014, 06:41:43 PM
I am using the following server blocking call:

with AppData.PLClientModule do
begin
  ModuleFileName := '/LOGIN';
  Prepare('UserIsOnline');
  Param.asString['inUserName'] := 'admin';
  Execute;
  FUserIsOnline := LastResult.asBoolean;
end;

However, I am getting the following memory leak when shutting down the client:

An unexpected memory leak has occurred. The unexpected small block leaks are:

1 - 12 bytes: String x 2, Unknown x 2
13 - 20 bytes: TRtcInfo x 1, tPtrPool x 1, String x 9
21 - 28 bytes: tXObjList x 1, TRtcCritSec x 1
29 - 36 bytes: TRtcSocketClientThread x 1
37 - 44 bytes: TRtcHugeByteArray x 2
125 - 132 bytes: Unknown x 2
133 - 140 bytes: Unknown x 1
269 - 284 bytes: TRtcWinSocket x 1
349 - 380 bytes: TRtcSocketHttpClientProvider x 1
381 - 412 bytes: Unknown x 1

Is there anything I need to free?



Title: Re: Memory leak on client app shutdown
Post by: D.Tkalcec (RTC) on May 29, 2014, 06:48:00 PM
For a clean Client shut-down, when using multi-threaded connection components, you need to close the connection before closing the Application. This is done by using the "DisconnectNow" method on the TRtcHttpClient component. On the Server-side, use the "StopListenNow" method on the TRtcHttpServer component.

That is also explained in this FAQ topic (https://rtcforum.teppi.net/index.php?topic=95.0).

Best Regards,
Danijel Tkalcec


Title: Re: Memory leak on client app shutdown
Post by: thomh on May 29, 2014, 07:11:19 PM
That does reduce the leakage a little. After calling DisconnectNow I get:

1 - 12 bytes: Unknown x 2
13 - 20 bytes: TRtcInfo x 1, tPtrPool x 1, String x 6
21 - 28 bytes: tXObjList x 1, TRtcCritSec x 1
29 - 36 bytes: TRtcSocketClientThread x 1
37 - 44 bytes: TRtcHugeByteArray x 1
125 - 132 bytes: Unknown x 1
133 - 140 bytes: Unknown x 1
269 - 284 bytes: TRtcWinSocket x 1
349 - 380 bytes: TRtcSocketHttpClientProvider x 1
381 - 412 bytes: Unknown x 1


Title: Re: Memory leak on client app shutdown
Post by: D.Tkalcec (RTC) on May 29, 2014, 07:16:39 PM
The leak report shows a thread still running, which either means that DisconnectNow wasn't called on all connections, or that the method call was interrupted, or called too late. You need to call the DisconnectNow method before any objects which might be used by the connection are destroyed and make sure the components will NOT be used after that. For example, by calling the DisconnectNow method on all TRtcHttpClient components at the end of the OnCloseQuery event on your main Form.

Best Regards,
Danijel Tkalcec


Title: Re: Memory leak on client app shutdown
Post by: thomh on May 29, 2014, 07:28:36 PM
I had the TRtcHttpClient.MultiThreaded = True. Setting it to False fixed it. Since my client will only be using blocking calls, I guess there no need to have that property set to True.


Title: Re: Memory leak on client app shutdown
Post by: D.Tkalcec (RTC) on May 29, 2014, 07:34:50 PM
If your client will only be using blocking calls, you can also set the "Blocking" property of the TRtcHttpClient component to TRUE. That will make use of a blocking WinSock API instead of the Async WinSock API, eliminating the need of a message queue and resulting in the blocking calls to be executed slighly faster. Setting the "useProxy", "useWinHTTP" or "useSSL" property to TRUE would have the same effect, since these properties work by using blocking APIs.

Best Regards,
Danijel Tkalcec


Title: Re: Memory leak on client app shutdown
Post by: thomh on May 29, 2014, 08:14:24 PM
Thanks for your help, Danijel.