Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help In System.GC

 
Koh Khai Huat
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

i am doing a game programming in J2ME, I have alot of memory issue to hadle and i heard of the System.gc() method to call the garbage collector to collect the garbage. And i heard from others that when u call the Collector it does not stright away comes in and collect the garbage. So i would like to find out which is the most effective way to do garbage collection in the mobile game application. i am open to any suggestion. thanks in advance

regards,
Jason
 
java freshman
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My colleague said after call System.gc(), sometime also need to call Thread.sleep(500); to let the device have time to collect resource.

You can also try to unload all useless graphics (such as splash)
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Java Freshman"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no way to force garbage collection. Calling System.gc() is only a *suggestion* and the JVM is likely to ignore it. Even using Thread.sleep() will not guarantee that the garbage collector runs.

Layne
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternatively, you can use Runtime.getRuntime().gc() - But this does not guarantee GC either. You are basically left with no option but to call either of these methods and cross your fingers hoping the GC will run.

But, before the JVM crashes throwing OutOfMemoryError, the GC would surely be run once - A Silver lining.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic