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 {
						serverSocket.receive(packet);
						byte messageType = gameBytes[0];
						byte[] BAclientReceivedFrom = new byte[4];
						BAclientReceivedFrom[0]=gameBytes[1]; //client number in packet (from)
						BAclientReceivedFrom[1]=gameBytes[2];
						BAclientReceivedFrom[2]=gameBytes[3];
						BAclientReceivedFrom[3]=gameBytes[4];
						int clientNum=this.byteArrayToInt(BAclientReceivedFrom);
						System.out.print(" m-"+messageType+" from"+clientNum);
						
						clientsHaveSentPacket[clientNum]=true;
						
						//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) {
							System.out.println("all");
							
							
							//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?
LVL 1
beavoidAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
beavoidAuthor Commented:
Hi Carl
I'd really appreciate it if you took a look at my question about an RTS java skeleton.

here

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Computer Games

From novice to tech pro — start learning today.