Skip to content

Commit

Permalink
Merge pull request #456 from getbouncer/awush-fix-memory-leak-double-…
Browse files Browse the repository at this point in the history
…camera-unbind

Fix memory leak and double camera unbind
  • Loading branch information
awush-stripe authored Sep 24, 2021
2 parents 012d79a + c8a61a2 commit ea36197
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ buildscript {

dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

plugins {
id 'org.jetbrains.kotlin.plugin.serialization' version "1.4.32"
id 'org.jetbrains.kotlin.plugin.serialization' version "1.5.31"
id 'org.jetbrains.dokka' version '1.5.0'
id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
}
Expand Down
2 changes: 2 additions & 0 deletions cardscan-demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ dependencies {
testImplementation "androidx.test:runner:1.4.0"
testImplementation "junit:junit:4.13.2"
testImplementation "org.jetbrains.kotlin:kotlin-test:1.5.30"

debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,7 @@ open class CardScanActivity :
frames: Collection<SavedFrame>,
isFastDevice: Boolean
) {
cameraAdapter.unbindFromLifecycle(this@CardScanActivity)
this@CardScanActivity.pan = pan

launch(Dispatchers.Default) {
scanFlow.launchCompletionLoop(
context = this@CardScanActivity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ abstract class CardScanBaseActivity :
* A final result was received from the aggregator.
*/
override suspend fun onResult(result: MainLoopAggregator.FinalResult) = launch(Dispatchers.Main) {
changeScanState(ScanState.Correct)
cameraAdapter.unbindFromLifecycle(this@CardScanBaseActivity)
resultListener.cardScanned(
pan = result.pan,
frames = scanFlow.selectCompletionLoopFrames(result.averageFrameRate, result.savedFrames),
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.getbouncer.scan.framework.util.getOsVersion
import com.getbouncer.scan.framework.util.getPlatform
import com.getbouncer.scan.framework.util.getSdkFlavor
import com.getbouncer.scan.framework.util.getSdkVersion
import com.getbouncer.scan.framework.util.memoize
import com.getbouncer.scan.framework.util.retry
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -346,7 +345,7 @@ private data class DeviceIdStructure(
val d: String
)

private val buildDeviceId = memoize { context: Context ->
private val buildDeviceId = cacheFirstResult { context: Context ->
DeviceIds.fromContext(context).run {
Base64.encodeToString(
Config.json.encodeToString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import android.util.Size
import androidx.annotation.CheckResult
import com.getbouncer.scan.framework.Config
import com.getbouncer.scan.framework.exception.ImageTypeNotSupportedException
import com.getbouncer.scan.framework.util.cacheFirstResult
import com.getbouncer.scan.framework.util.mapArray
import com.getbouncer.scan.framework.util.mapToIntArray
import com.getbouncer.scan.framework.util.memoize
import com.getbouncer.scan.framework.util.toByteArray
import java.io.ByteArrayOutputStream
import java.io.IOException
Expand All @@ -30,7 +30,7 @@ import kotlin.experimental.inv
/**
* Get the RenderScript instance.
*/
val getRenderScript = memoize { context: Context -> RenderScript.create(context) }
val getRenderScript = cacheFirstResult { context: Context -> RenderScript.create(context) }

/**
* An image made of data in the NV21 format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data class Device(
val platform: String
) {
companion object {
private val getDeviceDetails = memoize { context: Context ->
private val getDeviceDetails = cacheFirstResult { context: Context ->
Device(
ids = DeviceIds.fromContext(context),
name = getDeviceName(),
Expand All @@ -44,7 +44,7 @@ data class DeviceIds(
val androidId: String?
) {
companion object {
private val getDeviceIds = memoize { context: Context ->
private val getDeviceIds = cacheFirstResult { context: Context ->
DeviceIds(
androidId = getAndroidId(context)
)
Expand Down

0 comments on commit ea36197

Please sign in to comment.