Closed hanslovsky closed 5 years ago
FetcherThreads
already has a shutdown()
method, and I just implemented SharedQueue.shutdown()
https://github.com/bigdataviewer/bigdataviewer-vistools/commit/a6987d49e5373a13f4b70bfc918dda5345a70ade. Because SharedQueue
/FetcherThreads
can/should be shared between images and you have a handle on them from the outside, we should not add anything to CachedCellImg
for this.
For IoSync
/DiskCachedCellImg
, we should definitely add IoSync.shutdown()
. And then probably just add a close()/shutdown()
to DiskCachedCellImg
that shuts down it's IoSync
.
Thanks for looking into this! Let me know if there is anything I can contribute.
FetcherThreads
already has ashutdown()
method, and I just implementedSharedQueue.shutdown()
bigdataviewer/bigdataviewer-vistools@a6987d4. BecauseSharedQueue
/FetcherThreads
can/should be shared between images and you have a handle on them from the outside, we should not add anything toCachedCellImg
for this.
Great, that should be a fairly easy solution.
SharedQueue
constructor? A number that is large enough to hold all expected mipmap levels? For
IoSync
/DiskCachedCellImg
, we should definitely addIoSync.shutdown()
. And then probably just add aclose()
/shutdown()
toDiskCachedCellImg
that shuts down it'sIoSync
Currently, the DiskCachedCellImg
does not know its IoSync
. It only knows that it has a Cache
. We could be more specific about the kind of Cache
that is being passed and then require it to be a cache that exposes its loader (or always require an IoSync
loader). I could also not use the DiksCachedCellImgFactory
and create the Cache
where I need to have direct ownership of the IoSync
.
- Do you have a good intuition for what is a reasonable number of priorities in the
SharedQueue
constructor? A number that is large enough to hold all expected mipmap levels?
Yes.
- And then, should lower resolution mipmap levels be loaded with higher priority (less data in total and something can be on the screen more quickly)?
Yes, that's the idea. At least that's how I do it in BDV.
Currently, the
DiskCachedCellImg
does not know itsIoSync
. I would at it as a member variable toDiskCachedCellImg
.
If you want to work on this, that would be great.
For
IoSync
/DiskCachedCellImg
, we should definitely addIoSync.shutdown()
. And then probably just add aclose()/shutdown()
toDiskCachedCellImg
that shuts down it'sIoSync
.
As far as I know, there is currently no way to shutdown a cache. In particular that means that the resources of a
CachedCellImg
or a volatile wrapped cell cannot be garbage collected because the threads that are created insideIoSync
orFetcherThreads
are not stopped. In particular forIoSync
, where theWriter
is an inner class, that means that resources stay alive until the JVM is shutdown.I think it does make sense to add a
shutdown
/stop
/close
/... to make sure that resources are freed when a cache is discarded, e.g. aDiskCachedCellImg
is not being used anymore. The question is, at what level shuld taht be introduced? Can it be at the root(s) of theCache
hierarchy, i.e. inAbstractCache
andCacheLoader
?One caveat is that downstream caches may not know about the shutdown, e.g. a volatile-wrapped
CachedCellImg
. It would be the responsibility of the caller to ensure that shutdown is called in a sane way.Related links: https://github.com/saalfeldlab/paintera/issues/309 https://gitter.im/saalfeldlab/general?at=5d5d832e7d3c163641170b8f https://gitter.im/imglib/imglib2?at=5d5d89cb67969726f93df923