user3276091
user3276091

Reputation: 263

Java - Remove thread from memory

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

Answers (2)

Ralf H
Ralf H

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

Marko Topolnik
Marko Topolnik

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

Related Questions