mbedward / jaitools

Raster image processing for Java developers
17 stars 15 forks source link

DiskMemTileCache leaking threads #223

Open akosmaroy opened 11 years ago

akosmaroy commented 11 years ago

I'm running a code which creates a log of DiskMemImage objects, and I've found that each new object creates and leaves a daemon thread running, even after it is disposed. I looked at the code, and it seems DiskMemImage.createGraphics() will create a new a new cache with createNewCache(), which creates a new thread in its constructor via startTilePolling().

but this thread is never stopped and gotten rid of.

it's not stopped in the dispose() call to the Graphics2D object returned. it is also not stopped & destroyed in the dispose() call of DiskMemImage itself. actually, it seems the function that is supposed to destroy this thread, DiskMemTileCache.stopTilePolling(), is only called by setTilePollingInterval(), where a new thread is created immediately - but it is never called to actually destory this thread for good.

akosmaroy commented 11 years ago

here is a proposed patch to fix the issue: https://gist.github.com/akosmaroy/4959548

the reason why there is no unit test, is that that the freeing up of the thread is done by calling tilePollingService.shutdown() - where there is no accessor tilePollingService, thus it is not possible to verify from a test that indeed it has shut down