| 186 | } |
| 187 | |
| 188 | private fun doCleanup() { |
| 189 | val currentTime = System.nanoTime() |
| 190 | |
| 191 | synchronized(cachedBitmaps) { |
| 192 | val it = cachedBitmaps.iterator() |
| 193 | while (it.hasNext()) { |
| 194 | val cachedBitmap = it.next() |
| 195 | |
| 196 | if (currentTime >= cachedBitmap.expirationTime) { |
| 197 | // logger.info("Discarding expired Bitmap of size ${cachedBitmap.getBitmap().width}x${cachedBitmap.getBitmap().height}") |
| 198 | it.remove() |
| 199 | cachedBitmap.destroy() |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if (cachedBitmaps.isEmpty()) { |
| 204 | cleanUpTimer?.cancel() |
| 205 | cleanUpTimer = null |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | companion object { |
| 211 | // How long we keep the bitmaps alive after they were released |