I have an Android application where I use HashMap where I keep my Threads (values) each executing a task (Runnable). To identify the Threads I use Strings as keys. The Threads are alive as long as they execute a task what is usually not very long. The problem is that they seem to never been released by GC after finishing and being removed from the HashMap (and they are not referenced from anywhere else). If I create a dump of my application there are as many of my tasks in memory as started through the life of the application. Have tried to use HashSet instead but with the same result.
In code I start them with this few lines:
Thread image_fetch_thread = new Thread(new ImageFetchTask(image_url, this));
this.running_image_fetch_threads.put(image_url, image_fetch_thread);
image_fetch_thread.start();
and at some point later they become removed:
this.running_image_fetch_threads.remove(image_url);
Why GC don't like to collect them?