| 157 | } |
| 158 | |
| 159 | private fun onBitmapUnused(cachedBitmap: CachedBitmap) { |
| 160 | synchronized(cachedBitmaps) { |
| 161 | if (cleanUpTimer == null) { |
| 162 | val timer = Timer("Valdi BitmapPool GC") |
| 163 | cleanUpTimer = timer |
| 164 | |
| 165 | timer.scheduleAtFixedRate(object: TimerTask() { |
| 166 | override fun run() { |
| 167 | doCleanup() |
| 168 | } |
| 169 | }, bitmapDestroyDelayMs, bitmapDestroyDelayMs) |
| 170 | } |
| 171 | |
| 172 | if (cachedBitmap.isUnused && !cachedBitmaps.contains(cachedBitmap)) { |
| 173 | cachedBitmaps.add(cachedBitmap) |
| 174 | cachedBitmap.expirationTime = System.nanoTime() + (bitmapDestroyDelayMs * 1000000L) |
| 175 | cachedBitmap.markDirty() |
| 176 | |
| 177 | cleanUpTimer?.schedule(object: TimerTask() { |
| 178 | override fun run() { |
| 179 | if (cachedBitmap.isUnused) { |
| 180 | cachedBitmap.prepareForReuse() |
| 181 | } |
| 182 | } |
| 183 | }, 0L) |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | private fun doCleanup() { |
| 189 | val currentTime = System.nanoTime() |