• 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

How to destroy an object

 
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
I was wondering how to destroy an object or variable. Do I need it to do explicitly?
See the problem is that I have made one stand Alone application which extends with Thread. It sometimes get hanged. I have a feeling that it might becuase of that it has a lot of variables and object (yes I am trying to cut it short) and they are biting computer memory. Though I am using Flush() Method, but in vain.
Can some body help me?
Arun
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can set un referenced objects to null just to indicate that it's no longer needed. You can also use Runtime.getRuntime() to "Suggest" that the GC run, but you can't force it or even guarantee it will run at all.
------------------
Bosun
SCJP for the Java� 2 Platform
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Arun,
There is no way to explicitly destroy an object in Java. The most you can do is set all it's references to 'null' and eventually the garbage collector will look after it.
Have you tried increasing the memory? You can use <code>java -Xms8m classname</code> to give the application 8mb of heap memory vs the standard 2mb.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Co-author Mike Meyers' Java 2 Certification Passport
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic