Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  GarabgeCollection in Gaming  (Read 2159 times)
0 Members and 1 Guest are viewing this topic.
Offline shareme

Junior Member




Java games rock!


« Posted 2003-07-12 11:45:36 »

You guys may have not noticed get JUly issue of Java Develoeprs Hournal and read the article at page 39, Garabage Collection Pauses..

The code is also useable in most Java Games..Smiley

The gener cocnept of the article is to setup a patern of garbage collection that gets rid of pauses when apps run for long periods of tiem and other gc hicups you may have noticed..




Offline gregorypierce

Senior Member




I come upon thee like the blue screen of death....


« Reply #1 - Posted 2003-07-13 05:17:55 »

It will be a couple of days before I can get to the bookstore so cut to the chase and tell us about it man  Grin

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Offline gregorypierce

Senior Member




I come upon thee like the blue screen of death....


« Reply #2 - Posted 2003-08-16 06:13:30 »

Well ShareMe seems to have fallen off the planet so I will describe the gist of it.

* Make sure you don't have objects sitting around in collections
* Make sure you set references to null
* Do manual garbage collections at point when you know you just allocated a bunch of temporary memory (loading files, images, etc)
* (more useful), build a system that performs regular garbage collection sweeps. This is obvious, but not generally used or advised by Sun. It works well (I've actually tested it) because you are collecting at a regular interval that is tunable for your application in a deterministic manner - and it means that when the collection happens, there isn't as much stuff to collect because you've gone out of your way to keep heap trash to a minimum


So in general - its not something that you shouldn't already know as a Java programmer, its not until you actually use it under load that you really appreciate it. Its the difference between your large application running and being a stuttering mess Smiley

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #3 - Posted 2003-08-18 22:59:07 »

What I found interesting is how the periodic forced collections go completely against the advice of Sun which has always stated (with hotspot at least) that you should rarely, if ever, call System.gc()

It doesn't seem like something you should be calling (except after initialisation steps etc. like you listed above) for the most part either.   It may work... but I don't have to like it Smiley

Setting references to null explicitly makes sense, but is also a bit ugly.. you don't want null object handles hanging around in general.  If it wasn't a source formatting nightmare, I would try to do the same sort of thing by introducing new scopes for variables that you only need for a short while, eg:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
void blah()
{
   // do some clever stuff
  {
          Set stuff = new HashSet(); // need a set for something
         // do more wonderfully clever things with stuff
  }
   // keep going, but 'stuff' is now out of scope
  // so it can be collected AND I can't reference it.
}

Offline DrQuincy

Junior Member




Vwls hv bn bnnd!


« Reply #4 - Posted 2003-08-19 14:15:36 »

Quote


* (more useful), build a system that performs regular garbage collection sweeps. This is obvious, but not generally used or advised by Sun. It works well (I've actually tested it)...


Hi there,

if manual gcs do work why aren't they used or advised by Sun?
Huh
Thanks  Cool
Offline tortoise

Junior Member




<3 Shmups


« Reply #5 - Posted 2003-08-19 18:23:47 »

Why no objects sitting around in collections? Eats up free memory causing the GC to scrounge around? Goes against what a lot of people always thought, keep references to dead objects until it's "safe" to have them collected. Although that view always struck me as based on assumption with little evidence to back up it works. I think a better approach overall is to just rework sections of your program that generate a lot of temporary objects.

I read an article on IBM's site (which for the life of me I can't find anymore) that talked about setting the minimum percentage of free memory before the GC kicks in to quite high, and increase the size of the heap while you're at it (both command line options to the jvm) and you essentially render the gc immobilized unless the situation become really dire. I tested it a tad and it seemed to work, but I've never had any crucial situation where I could see if it really helps or not.

But despite all of that, is gc-ing really an issue these days? I hardly, if ever, notice any jerks or slowdowns from the gc in my programs.
Offline troggan

Junior Member




no guts no glory


« Reply #6 - Posted 2003-08-19 18:40:59 »

I think modern GC are very good in finding out when to start cleaning everything. The new GC's are so good, that I never have seen any problems in my apps. Btw: I have some very memory comsuming apps that use up to 1 gig of ram and the gc was ABSOLUTLY no problem. Sometimes it's even bad to call it on your own. I have speeded up the code of a coworker just with removing the GC calls. But try for your self Smiley

(http://www.wannawork.de) - Will work for food
(http://tvbrowser.org) - Java EPG
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #7 - Posted 2003-08-19 20:35:30 »

That's what I would have said, but this report was done with a modern VM.  They concluded that a periodic call to System.gc() improved the GC pause times.  I guess the idea was that it had less to do each time because it happened more frequently.  
I figured the pause time would be relative to the size of the heap, not just the number of dead objects.. but what do I know Tongue

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (16 views)
2014-07-30 21:08:39

Riven (22 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!