Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Destroying Objects

Status
Not open for further replies.

clare

Programmer
Dec 10, 2000
1
GB
I am creating lots of different objects within objects for a GUI based application, I am using this.dispose
to free up the resources but i am finding that after a while the system slows down and eventually stops,
is this becuase the objects remain in memory? if so how can i delete them. Each object is being created
in a different class so i cannot set the object to null from its own class as it won't compile as it doesn't recognise the objects
thanks
 
Um well java is supposed to do garbage collecting automatically so as soon as you no longer use an object it should disappear from memory. What i've found is that java waits until the cpu utilisation goes down below a threshold before it does its garbage collecting, but java uses so much memory that often it doesn't get done for quite some time. The only thing i can think of is to force garbage collection at a point in your program. Unfortunately I can't find any refference on how to do this. Also have you got any threads running? I was involved in developing a simulation system in java and the use of threads as well as gui stuff really slowed things down.

Chris Packham
kriz@i4free.co.nz

A thousand mokeys at a thousand machines, it happened, it got called the internet.
 
Java wont reclaim memory until you run out of it.

You can manually kick start the garbage collector using System.gc() from memory. Be warned that this may cause the system to grind to a halt for a few seconds so be careful when you call it.

Threads are far more likely to cause the kind of slowdown that you spoke of than is memory shortage. Just something to think about.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top