W
WonderboyFromMars
Hello everyone.
I have a problem with instanciating many threads and the destruction of
these objects.
Does the garbage collector actually delete threads?
I'm writing a network application which has to create 2 threads which
read and write to PipeStreams on each new conenction. And I have alot
of
connections. the problem is that the application has a big mem.-leak
and
I narrowed it down to the fact that the Garbage Collector actually
won't
clean up stopped or interrupted threads. JProfiler tells me that more
an
more instances of the threads are created although the threads are
inactive (the thread-column in the Windows taskmanager jumps to a
thread-peak but drops down to the actual number of threads). I think
that the thread memory still remains on the heap. I'm actually a c++
programmer who does eventually something in java the code looks
something like this
while(...)
{
socket.accept()
ThreadWorker1 tw1 = new ThreadWorker1(...);
ThreadWorker2 tw2 = new ThreadWorker2(...);
tw1.start();
tw2.start();
}
the threadworkers start their own threads internally which get
interrupted when the work is done. does this construction lead to
mem.-leaks? If I let the app run for let's say an hour and then look at
the instance count of ThreadWorker1 and ThreadWorker2 in JProfiler, I
can see that the instance count never goes down but up (after 1 h i
have
100 instances of TW1 and TW2). The threads are definitly stopped
sometime (or Windows Taskmanager is lying ) but obviously never
released.
Thanks in advance
Anusch
I have a problem with instanciating many threads and the destruction of
these objects.
Does the garbage collector actually delete threads?
I'm writing a network application which has to create 2 threads which
read and write to PipeStreams on each new conenction. And I have alot
of
connections. the problem is that the application has a big mem.-leak
and
I narrowed it down to the fact that the Garbage Collector actually
won't
clean up stopped or interrupted threads. JProfiler tells me that more
an
more instances of the threads are created although the threads are
inactive (the thread-column in the Windows taskmanager jumps to a
thread-peak but drops down to the actual number of threads). I think
that the thread memory still remains on the heap. I'm actually a c++
programmer who does eventually something in java the code looks
something like this
while(...)
{
socket.accept()
ThreadWorker1 tw1 = new ThreadWorker1(...);
ThreadWorker2 tw2 = new ThreadWorker2(...);
tw1.start();
tw2.start();
}
the threadworkers start their own threads internally which get
interrupted when the work is done. does this construction lead to
mem.-leaks? If I let the app run for let's say an hour and then look at
the instance count of ThreadWorker1 and ThreadWorker2 in JProfiler, I
can see that the instance count never goes down but up (after 1 h i
have
100 instances of TW1 and TW2). The threads are definitly stopped
sometime (or Windows Taskmanager is lying ) but obviously never
released.
Thanks in advance
Anusch