• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 565
  • Last Modified:

Java RTS game server managing waste data.

Hi, in my RTS server code below.. I accept packets and clip off the packet's data for analysis. What is the best way to keep each client's byte[] array data, and toss it out. I'm worried about congestion and memory blowouts. Thanks
If I release each client's data byte[] at the bottom of the loop, will garbage collection be fast enough to ward off blowouts?

This is just the skeleton of the server loop

                                        byte[] gameBytes = new byte[MsgLength];
					packet = new DatagramPacket(gameBytes,MsgLength);
					try {
						byte messageType = gameBytes[0];
						byte[] BAclientReceivedFrom = new byte[4];
						BAclientReceivedFrom[0]=gameBytes[1]; //client number in packet (from)
						int clientNum=this.byteArrayToInt(BAclientReceivedFrom);
						System.out.print(" m-"+messageType+" from"+clientNum);
						//check if all clients have sent a packet for this frame
						boolean allClientsHaveSentApacket=true;
						for (int i=0; i<this.joinedClientCount;i++) {
							if (!clientsHaveSentPacket[i])                allClientsHaveSentApacket=false;
						if (allClientsHaveSentApacket) {
							//handle each client's message
							//and then set sent check array to  false
							for (int i=0; i<this.joinedClientCount;i++) {

Open in new window

will lastly releasing gameBytes be correct?
1 Solution
mccarlIT Business Systems Analyst / Software DeveloperCommented:
You shouldn't worry too much about how or when the GC will do its job. It will guarantee to do it's best to clean up memory that is available for GC whenever memory is needed for something else (or a number of other reasons).

Are you getting real issues at runtime that you are trying to overcome? If you are just trying to anticipate potential issues, then I would say don't worry about this. The GC is a pretty advanced piece of code and I'll bet that it will be smart enough to figure what it needs to do, and unless you are doing some pretty way-out stuff, it will do it's job well. The simple code above, ie. just allocating objects/arrays using them and then letting them go out of scope, should be no problem for the GC to handle.
beavoidAuthor Commented:
Hi Carl
I'd really appreciate it if you took a look at my question about an RTS java skeleton.


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now