Thursday, September 20, 2007

Work around memory leaks with Java socket

Object input/output streams, which are usually used with Java sockets have holes that leak memory. Basically, they maintain internal caches that store objects that were sent and received. As Java doesn't clear the caches automatically, they just keep growing and growing in size, until your application run out of memory. Calling reset() flushes the cache, but proves too slow to call every time an object is sent or received.
I explain the problem in more detail and describe the work-around, in the article here.