Clear questions and runnable code
get the best and fastest answer
Memory leak with socketby Biker (Priest)
|on Aug 14, 2002 at 13:07 UTC||Need Help??|
Biker has asked for the
wisdom of the Perl Monks concerning the following question:
I have an annoying socket related problem.
After a lot of trial and error I have found a work-around to the problem and my code is now functional.
Scenario:I have a 'server' application that opens a socket. It then loops around an accept() on the socket. Whenever a client connects, the server reads and (for testing purposes only) discards anything read. It never writes anything to the socket. This part works fine.
I have a test client that does nothing but connect to the server socket and then closes the socket. It writes nothing to the socket before closing it.
This creates a major memory leak in the client application.
If I let the client write some arbitrary text to the socket, the problem remains. But, if I let the client read from the socket, the memory leak goes away (?!?!). There was nothing there to read. The client immediately gets a logical end-of-file, but it will not leak memory.
Question:How can this be?
Code:This is a code snippet that reproduces the problem:
Everything went worng, just as foreseen.