Reputation: 263
I am creating a java desktop application that open a new JFrame (inside a thread) from another JFrame. Is there a way to remove a thread from the memory?
Upvotes: 1
Views: 5116
Reputation: 1474
There is no way to actually remove a Thread object from memory. Like with any other object, if there are no references to it, it will be garbage-collected the next time a gc runs.
Upvotes: 2
Reputation: 200138
A thread is not a Java object. It is a native resource (thread of execution). The thread will be "removed from memory" as soon as it has finished running its code.
From Java's perspective, the thread is dead as soon as its run()
method completes.
As for the Thread
instance in charge of a particular thread of execution, it behaves just like any other Java object and is reclaimable by the Garbage Collector as soon as no references to it exist (and the underlying thread is not alive).
Upvotes: 6