Hello Arno,

Just a mail to thank you again and maybe letting other people, running into the 
same problem, know how we solved our problem.

By tracking down those few bytes that did not get freed I noticed that I was 
not sure how and when client sockets get freed.
It is common to let the socket server create the socket clients and let the 
socket server free the clients again.
The clients can be used to do the per client handling.

Our per user handling is done in an object that accessed via an interface and 
is freed by dereferencing it.
So it me still be around when the socket server and it's client do not exist 
anymore.
This interfaced object uses a client socket for communication. It is created in 
the server's OnClientConnect.

The problem was that this interfaced object had a reference to a socket but had 
no means of knowing when this (client) socket was freed and thus invalid.
We solved the problem with an extra object that inherits from TWSocketClient 
and informs the user (the interfaced object) in its destructor that it is about 
to be freed. Then the user object knows it can't use the socket anymore.
This solved our problem.

So in the end it paid off to check why these few bytes were not release by the 
program.

Thank you again.

Henk van der Meer
www.timeservice.nl


-----Oorspronkelijk bericht-----
Van: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] Namens 
Arno Garrels
Verzonden: woensdag 21 september 2011 21:00
Aan: ICS support mailing
Onderwerp: Re: [twsocket] Loosing memory in TWSocketClient.TriggerSessionClosed

Henk van der Meer wrote:
> The thing is that if you leave the freeing up to windows you have no 
> means of checking for memory leaks.
> So I like my programs to free all their memory so I'm sure I haven't 
> forgotten anything.
> 
> If the client still lives then the owner, the server, must be alive 
> also.
> As far as I can tell the message postmessage sends (posts :-) ) is not 
> handled (anymore) so this memory won't get freed.
> Could it be the hidden window is destroyed before the socket server 
> is?

At least the message pump may no longer work, so in order to avoid this issue 
try to kill all clients and close their connections non-gracefully and 
synchronously by a call to method TWSocketServer.DisconnectAll before the 
TWSocketServer is destroyed.

--
Arno Garrels

> 
> Regards,
> 
> Henk van der Meer
> 
> 
> -----Oorspronkelijk bericht-----
> Van: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org]
> Namens Arno Garrels
> Verzonden: woensdag 21 september 2011 16:10
> Aan: ICS support mailing
> Onderwerp: Re: [twsocket] Loosing memory in 
> TWSocketClient.TriggerSessionClosed
> 
> Henk van der Meer wrote:
>> Hello,
>> 
>> I have an application that uses fastmm4 to track memory.
>> It informed me of an memory leak that I traced down to:
>> TWSocketClient.TriggerSessionClosed
>> 
>> This procedure does a New(PIdRec);
>> This record is only disposed of when the postmessage returns true.
> 
> No quite correct, if PostMessage returns False the memory is freed at 
> once, if PostMessage returns True it's freed in the message handler, 
> so a leak can only occur if PostMessage returned True and the message 
> is never processed, that however can most likely only happen when the
> TWSocketServer object is destroyed.    
> 
>> In my program this isn't the case.
>> Does somebody know how this is supposed to work?
> 
> I guess yuo see this leak once when the application shuts down, if 
> that is the case no worry, windows frees everything.
> 
>> One other thing I noticed. This record contains a reference to the 
>> client socket.
>> When this message that is posted is processed to late this socket 
>> does not exist anymore.
> 
> This message is sent to TWSocketServer's hidden window. On receipt the 
> sending client object is removed from the client list and freed.
> So basically one should not free a client object but rather close its 
> connection. One should also disconnect all clients before the
> application shuts down IMO.    
> 
>> 
>> Is there some convention I have to follow in creating and destroying 
>> clients?
> 
> Let TWSocketServer manage the client objects, it creates them so it 
> should free them as well.
> 
> --
> Arno Garrels
> --
> To unsubscribe or change your settings for TWSocket mailing list 
> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
> Visit our website at http://www.overbyte.be
--
To unsubscribe or change your settings for TWSocket mailing list please goto 
http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to