• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help In System.GC

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic