MCPcopy Create free account
hub / github.com/Snapchat/Valdi / onBitmapUnused

Method onBitmapUnused

valdi/src/java/com/snap/valdi/utils/BitmapPool.kt:159–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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()

Callers 1

releaseMethod · 0.80

Calls 5

containsMethod · 0.65
addMethod · 0.65
scheduleMethod · 0.65
TimerClass · 0.50
markDirtyMethod · 0.45

Tested by

no test coverage detected