Online Garbage Collection Article

Dear All,

I’ve just added an appendix to the Killer Game Programming in Java website about how to detect memory leaks and reduce garbage collection pauses.

It’s Appendix C, at the very bottom of the main page:
http://fivedots.coe.psu.ac.th/~ad/jg/

Comments are appreciated.

  • Andrew

I’ve only skimmed some key parts but it looks very good so far.

It might be a good idea to mention the new profiler for NetBeans 5, even though it is still in beta.

Is there any reason to don’t post a HTML version of that pdf file?

Just a question 'cause Im udner deadline and generally lazy 8)

Do you talk about the newspace and the difference between short lived and long-lived objects at all? (Sometimes called the “eden”.)

From JDK5 forward I have had no gc pause problems at all by simply following two simple rules. Obejcts should be EITHER short lived or very long lived. Short lived objects are generally colletable without apparent pauses. Long lived ones can cause pauses and therefor should be treated like memory allocation in C and only released during pause periods like level changes.

Exactly what are you classifying as ‘short lived’? Recently (particularly for my scrolly shooter) I’ve only really worried about avoiding really short lived objects (mainly temporary Vector2f etc. used for per enemy/bullet per frame updates). Stuff like bullets - which can easily have multiple new objects per frame, and last for a couple of seconds - I can happily new and discard without any noticable framerate hit or jerkyness. And all without any sort of GC tuning I might add. 8)

The article uses standalone visualization tools, so doesn’t talk about support in NetBeans, Eclipse, etc.

I use PDF because it’s a cross-platform format that’s easy to generate from MS Word, and still looks like the original document.

There’s a lot about short and long-lived objects in the article.

Short-lived objects are collected from the young generation space (new space) after a few seconds. If they live longer, they’ll eventually be moved to the old generation space (tenured space). GC from the tenured space can be a factor of 10 slower than the new space, so it may be useful to adjust the space sizes to keep objects in the new space.

But, like everything, if your application doesn’t have a problem with GC, then there’s no need to fine-tune it.

  • Andrew

Yup. And I wouldnt even worry about those unless the cost of creating them is heavyweight.

In a quick and dirty port of a game app i have to write a fake socket provider layer and was allocating multiple Buffer objects all up and down the chain for each pcaket.

I saw NO hit 8)

I love the newspace and how they finally have it tuned :slight_smile:

Just imagine how little work the GC will have to do when escape analysis gets into 6.0 :slight_smile: Truly freed from the shackles of performance worries vs. design at last.

Cas :slight_smile:

Actually PDF is format created and maintained by Adobe, so it’s not exactly crossplatform any more than PS or DJV, and it’s incredibly hard to download on computer especially compared to HTML file (You don’t have bandwidth limits on your site right? ~_^). Also it’s kinda hard to read without viewer.
(Actually PS is harder to read, because I still didn’t managed to add a nice PS reader on my computer.)

UM I disagree. Adobe works very hard to keep readers availabe on just about every paltform knwon to man. Ergo it may not be free but it is cross paltform.

As an aside tangential to the point, but not necc to your response, they also publish that standard in public. I wrote a PDF viewer in Java years ago. The only thing that prevented me from releasing it is that PDF uses LZW and at the time LZW was controlled by Univac.

[quote] and it’s incredibly hard to download on computer especially compared to HTML file
[/quote]
How it harder then any other file?? Comapring it to HTMl isnt a very fair comparison because PDF is a complete page markup langugage. HTMl is a highly limited rpesentation language. Aditionally, PDF gives you exact control over how the end product looks on all viewers, HML does not.

Viewer is free. Go to Adobe’s site and download.

Alas because of my neighbourds, I’m still on dial - up pay per minute. Going to adobe site and download something is completely ot of my fiscal posibilities. Not to mention the HD space on computer that I use for Internet connection is limited too much to alow instalation of Adobe reader.

HTML 64 KB <<< PDF 640 KB

Of course HTML has another helpful features, It’s easirer for reading, and it alows better indexing and searching. (Not to mention the possibility to take an image file and by irphanviewer use a few filters to look at specific part of the image.)

Imposibility of reformating PDF files is also sometimes problematic. You know some documents were formated for printing, not for viewing on computer screen. In fact they are HARD to read because PDF hold formating so well.

[tr]c[/tr] [tr] c[/tr]

So summary.
[tr] [td] PDF [/td] [td] HTML[/td] [td] simple TXT [/td] [td]RTF[/td][/tr]
[tr]
[td]Ease of compresion [/td] [td]0.8 (1.25x) [/td] [td] (majority at least 2.4x up to 5x) [/td] [td]2.2 up to 4.8 [/td] [td]majority 2.4x[/td][/tr][tr][td]Proxy caching [/td] [td] x [/td] [td]yes [/td] [td] yes [/td] [td] yes[/td][/tr[tr]][td]Refurmating possibile [/td] [td]no [/td] [td] yes (by editor or by hand) [/td] [td] yes (easy) [/td] [td]need wordprocessor[/td][/tr]
[tr][td]indexing [/td] [td] by Adobe reader could be 30 min [/td] [td]yes standard F3 on windoze, or MC, or by easy to write program [/td] [td] the same as HTML [/td] [/tr]
[tr][td]size on disk for 10000 files [/td] [td]freekingly high 860KB - 120MB/file [/td] [td]manageable [/td] [td] easy [/td] [td]kinda easy[/td][/tr]
[tr][td]Could show intention of developer well[/td]
[td] yes [/td] [td] yes [/td][td] could [/td] [td]could +formated[/td][/tr]

[tr][td]error detection [/td] [td]yes [/td] [td] no [/td] [td] no [/td] [td]just rarely yes[/td][/tr][tr][td]Other isues [/td][td] too static [/td] if [td]not careful could be too wide, pople are using bad tools to create HTML [/td] [td]x [/td] [td] badly readable by notepad[/td][/tr]

Other Adobe reader startup is 15-20 sec, it shows that ugly patent numbers on the startup. Incompatibilities between versions, and 2.5 hours between I could download PDF and look at it at my development computer.

This is short summary what I have against PDF.

Um. Its only 37MB. Do you have a Starbucks in your area? Go, get a cuip of cofee, and downlaod it on their wireless 8). Thats what Im doign on this laptop right now, takes abouit 2 min.

As for HD space… Staples just ahd a 200gig hard drive on sale for 20 bucks this weekend. Thats 10 cents a gig. Which means the space for reader is about 40 cents.

I’m sorry, I feel for you, but if your resourcesa re THAT far below what is standard on even cheap computers today you really can’t expect people to cater to it.

Sorry but I insist that this thread should get back on topic.
I was actually LEARNING something before this thread went into HTML vs PDF.
Thanks.

PS: Andrew Davison I really loved your piece on the GC. I even had to show it to my friend.
It helped me understand the concepts behind the GC and how it should be used.

EDIT: Spelling.

Fair 'nuff.

I’ve tried to tweak the garbage collection adjusting the parameters of heap size, new heap size, using parallel GC, etc. but my animations remain abrupt (I just use Java2D for some scrolling sprites). I have also noticed that the -XX:MaxGCPauseMillis doesn’t seem to apply to full GC so, in my case, it’s part of the problem.

Anyway thank you Andrew for the document, it has been a valuable help.
Guillaume