We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

sue_impact
Posts: 6
Joined: Fri Feb 03, 2006 3:07 pm

Java service memory leak

I have a problem with my Java service running out of memory. The code is essentially:

welcomeSocket = new ServerSocket(triggerPort);
welcomeSocket.setSoTimeout(3000);
while(running) {
try { connectionSocket = welcomeSocket.accept();
if (connectionSocket != null) {
ReaderThread t = new ReaderThread(connectionSocket.getInputStream(), connectionSocket.getOutputStream());
t.start();
}
} catch(SocketTimeoutException timeOutEx) {}
}

Using some memory leak analysis software the problem seems to be that welcomeSocket.accept() creates a number of objects that are never garbage collected. I can't find a way of getting rid of these objects while still allowing the new thread (which uses the same port) to work.

If I incremented a variable in the loop and exited the loop when it reached a certain number would this stop the service and allow the automatic restart to kick in, clearing the memory in the process? Any other suggestions for resolving the problem?

Thanks

Sue
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi Sue,

First note that our Java Service tutorial is just an example, the code is not optimized for commercial use.

However an object is garbage collected when gets out of scope. So in order to investigate the problem send the Java code (support at advancedinstaller dot com) and tell us what analysis software you are using to determine the memory leaks?

Regards,
Gigi
______________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com

Return to “Common Problems”