Re: [twsocket] properly closing a TWSocket

2007-04-09 Thread Arno Garrels
Markus Humm wrote:
>> Markus Humm wrote:
>> 
>>> My problem now is that FastMM reports a memory leak when the
>>> application is terminated.
>> 
>> The report attached says that an attempt has been detected to call
>> a virtual method on a freed object. That isn't a memory leak.
> 
> Yes I know. When I use the fulldebug switch I get was I reported here,
> but when I only use the normal fastMM of BDS2006 with
> ReportMemoryLeaks OnShutdown:=true then I get a messagebox showing me
> some memory leaks. 

So something is not freed when the instance of your client-WSocket is
freed. But even the message box of FastMM should give you a hint where
to search.

> The amout of them is corresponding to the number
> of connection closures (really wanted disconnects and disconnects due
> to my testing of the keepalive feature I implemented by plugging of
> the network cable). So I think these two are interrelated. 
 

> I can't
> really check it, because after the full report comes up a small
> window of windows is displayed that it has detected a crash in my app
> and that a faul report will be created. It terminates my app. then
> and writes this fastMM report into the eventlog.

When you debug the application is there an exception raised on exit?  

--
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html 
> 
>> 
>>> The rest of the app. works well enough, I
>>> can connect, send the data etc. disconnect, connect again etc. but
>>> every time I disconnect memory gets lost (some strings and something
>>> unknown, but only a few bytes (always the same amount as it seems)).
>> 
>> No idea, however most likely something in your code.
> 
> I thought so as well, but since I haven't yet any real clue I dared to
> ask here... ;-)
> 
>> 
>>> My TCP-server class (TWSocket descendant) holds a reference to the
>>> TWSocket as well which is explicitely set to nil when this socket's
>>> OnSessionClosed is called but directly after it a FreeAndNil(self)
>>> is called.
>> 
>> What is "Self"? Why don't you call FreeAndNil(Server.ClientWSocket)?
> 
> Ok, that would be a good thing I think but I fear it won't be the
> solution. 
> 
>> Do you create the client-WSocket with a non-nil owner?
> 
> No. Why should I?
> 
>> How do you free the client-WSocket when the application terminates?
> 
> I simply close it when I free the descendants instance.
> 
>> 
>> Even after a socket handle is closed the socket may exist for a
>> while, handled by the OS, nothing one must care about.
> 
> Ok. I'm simply more used to the concept of a object is dead as soon as
> it's freed. Only the memory allocated for it will still belong to the
> program, but can be overwritten just the next second with the next
> best thing...
> 
> Greetings
> 
> Markus
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] properly closing a TWSocket

2007-04-09 Thread Markus Humm
> Markus Humm wrote:
> 
>> My problem now is that FastMM reports a memory leak when the
>> application is terminated. 
> 
> The report attached says that an attempt has been detected to call
> a virtual method on a freed object. That isn't a memory leak.

Yes I know. When I use the fulldebug switch I get was I reported here, 
but when I only use the normal fastMM of BDS2006 with ReportMemoryLeaks 
OnShutdown:=true then I get a messagebox showing me some memory leaks. 
The amout of them is corresponding to the number of connection closures 
(really wanted disconnects and disconnects due to my testing of the 
keepalive feature I implemented by plugging of the network cable). So I 
think these two are interrelated. I can't really check it, because after 
the full report comes up a small window of windows is displayed that it 
has detected a crash in my app and that a faul report will be created. 
It terminates my app. then and writes this fastMM report into the eventlog.

> 
>> The rest of the app. works well enough, I
>> can connect, send the data etc. disconnect, connect again etc. but
>> every time I disconnect memory gets lost (some strings and something
>> unknown, but only a few bytes (always the same amount as it seems)).
> 
> No idea, however most likely something in your code.

I thought so as well, but since I haven't yet any real clue I dared to 
ask here... ;-)

> 
>> My TCP-server class (TWSocket descendant) holds a reference to the
>> TWSocket as well which is explicitely set to nil when this socket's
>> OnSessionClosed is called but directly after it a FreeAndNil(self) is
>> called.
> 
> What is "Self"? Why don't you call FreeAndNil(Server.ClientWSocket)?

Ok, that would be a good thing I think but I fear it won't be the solution.

> Do you create the client-WSocket with a non-nil owner?

No. Why should I?

> How do you free the client-WSocket when the application terminates? 

I simply close it when I free the descendants instance.

> 
> Even after a socket handle is closed the socket may exist for a while,
> handled by the OS, nothing one must care about. 

Ok. I'm simply more used to the concept of a object is dead as soon as 
it's freed. Only the memory allocated for it will still belong to the 
program, but can be overwritten just the next second with the next best 
thing...

Greetings

Markus
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] properly closing a TWSocket

2007-04-09 Thread Arno Garrels
Arno Garrels wrote:
[..]
> May be the next connection is accepted too early? You could post
> a custom message from OnSessionClosed and free and nil the
> ClientWSocket 
> from the message handler in order to be sure.
[..]

Please forget this part of my last message.

--
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] properly closing a TWSocket

2007-04-09 Thread Arno Garrels
Markus Humm wrote:

> My problem now is that FastMM reports a memory leak when the
> application is terminated. 

The report attached says that an attempt has been detected to call
a virtual method on a freed object. That isn't a memory leak.

> The rest of the app. works well enough, I
> can connect, send the data etc. disconnect, connect again etc. but
> every time I disconnect memory gets lost (some strings and something
> unknown, but only a few bytes (always the same amount as it seems)).

No idea, however most likely something in your code.

> My TCP-server class (TWSocket descendant) holds a reference to the
> TWSocket as well which is explicitely set to nil when this socket's
> OnSessionClosed is called but directly after it a FreeAndNil(self) is
> called.

What is "Self"? Why don't you call FreeAndNil(Server.ClientWSocket)?
Do you create the client-WSocket with a non-nil owner?
How do you free the client-WSocket when the application terminates? 
May be the next connection is accepted too early? You could post
a custom message from OnSessionClosed and free and nil the ClientWSocket
from the message handler in order to be sure.
 
> 
> If I use the full fastMM to trace the memory loss I get something
> slightly different or all the same that makes me wonder if my socket
> is freed correctly or who tries to call something from it. Using
> netstat I can see that the connection properly terminates after some
> seconds as expected (I only think it takes a little long to update
> the status display but that's a different matter I think and not
> avoidable).

Even after a socket handle is closed the socket may exist for a while,
handled by the OS, nothing one must care about. 

--
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html 
 

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


[twsocket] properly closing a TWSocket

2007-04-09 Thread Markus Humm
Hello,

my communication layer uses a TWSocket as TCP server socket and one for 
the actual communication as there will only be one connection at any 
give time. When the client requests a close of the connection I close 
the socket and in the OnSessionClosed I free it, because the server 
socket decides on it being nil or not wether to accept a new incomming 
session request or not. A invalid request will be temporarily accepted 
but closed at once.

My problem now is that FastMM reports a memory leak when the application 
is terminated. The rest of the app. works well enough, I can connect, 
send the data etc. disconnect, connect again etc. but every time I 
disconnect memory gets lost (some strings and something unknown, but 
only a few bytes (always the same amount as it seems)). My TCP-server 
class (TWSocket descendant) holds a reference to the TWSocket as well 
which is explicitely set to nil when this socket's OnSessionClosed is 
called but directly after it a FreeAndNil(self) is called.

If I use the full fastMM to trace the memory loss I get something 
slightly different or all the same that makes me wonder if my socket is 
freed correctly or who tries to call something from it. Using netstat I 
can see that the connection properly terminates after some seconds as 
expected (I only think it takes a little long to update the status 
display but that's a different matter I think and not avoidable).

Here is the fastMM trace (I've cut it after the first few bytes of 
memory dump as the rest is all 80hex):

2007/4/5 
15:45:53
FastMM has detected an attempt to call a virtual method on a freed 
object. An access violation will now be raised in order to abort the 
current operation.

Freed object class: TServerAnswerSocket

Virtual method: Offset +180

Virtual method address: 480CC4

The allocation number was: 5218

Stack trace of when the object was allocated (return addresses):
4030C6 [EMAIL PROTECTED]
403FB3 [System][TObject.NewInstance]
40437A [EMAIL PROTECTED]
485A72 
[tcpkommunikation.pas][tcpkommunikation][TServerAnswerSocket.Create][435]
486223 
[tcpkommunikation.pas][tcpkommunikation][TServerSocket.MyOnSessionAvailable][658]
481161 [WSocket.pas][WSocket][TCustomWSocket.TriggerSessionAvailable][5652]
47E087 [WSocket.pas][WSocket][TCustomWSocket.Do_FD_ACCEPT][4165]
47E17D [WSocket.pas][WSocket][TCustomWSocket.WMASyncSelect][4254]
47CB8B [WSocket.pas][WSocket][TCustomWSocket.WndProc][3174]
483E06 [WSocket.pas][WSocket][TCustomLineWSocket.WndProc][6533]

Stack trace of when the object was subsequently freed (return addresses):
4030E2 [EMAIL PROTECTED]
403FD1 [System][TObject.FreeInstance]
4043C5 [EMAIL PROTECTED]
483D92 [WSocket.pas][WSocket][TCustomLineWSocket.Destroy][6516]
404017 [System][TObject.Free]
4149BD [SysUtils][FreeAndNil]
485ED6 
[tcpkommunikation.pas][tcpkommunikation][TServerAnswerSocket.MyOnSessionClosed][540]
4811F1 [WSocket.pas][WSocket][TCustomWSocket.TriggerSessionClosed][5675]
4827F7 
[WSocket.pas][WSocket][TCustomSocksWSocket.TriggerSessionClosed][6061]
484AF1 [WSocket.pas][WSocket][TCustomLineWSocket.TriggerSessionClosed][6898]

The current stack trace leading to this error (return addresses):
47E063 [WSocket.pas][WSocket][TCustomWSocket.Do_FD_CLOSE][4157]
47E1AD [WSocket.pas][WSocket][TCustomWSocket.WMASyncSelect][4261]
47CB8B [WSocket.pas][WSocket][TCustomWSocket.WndProc][3174]
483E06 [WSocket.pas][WSocket][TCustomLineWSocket.WndProc][6533]
47CD07 [WSocket.pas][WSocket][XSocketWindowProc][3225]
77E3158F [GetTopWindow]
77E31DC9 [GetWindowLongW]
77E297D8 [GetParent]
77E193FB [GetPropA]
4732CD [Forms][TApplication.ProcessMessage]

Current memory dump of 256 bytes starting at pointer address 2449D50:
0C 1E 50 00 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 
80 80 80 80 80 80 80 80

Greetings

Markus
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be