RTC Forums
May 20, 2024, 01:13:44 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Memory leak on client app shutdown  (Read 4625 times)
thomh
RTC License+
****
Posts: 17


« 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?

Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 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.

Best Regards,
Danijel Tkalcec
Logged
thomh
RTC License+
****
Posts: 17


« Reply #2 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
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 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
Logged
thomh
RTC License+
****
Posts: 17


« Reply #4 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.
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #5 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
Logged
thomh
RTC License+
****
Posts: 17


« Reply #6 on: May 29, 2014, 08:14:24 PM »

Thanks for your help, Danijel.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.023 seconds with 15 queries.