I have the following function that starts a jsvc daemon for receiving UDP messages:
@Override
public void start() throws Exception {
byte[] buf = new byte[1
public void run() {
while(!stopped){
byte[] rcvMsg = incomingBinaryMessage;
MessageCreator tmc = new MessageCreator();
Message message = null;
try {
message = tmc.createMessage(rcvMsg);
System.out.println(message);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
This code does not appear to do any I/O. incomingBinaryMessage
is not a method invocation, it is an object reference to an existing byte[]
.
The loop runs repeatedly creating the same message over and over.
Normally GC should keep up with you since you're discarding the messages and MessageCreator
instance on every loop. However, the one piece of code you haven't shown, the constructor for Message
could be saving a reference to the messages (i.e. adding them to a map?) and preventing them from being GC'ed.