Skip to content

Commit

Permalink
Detach CtClass instances from the ClassPool as they are inspected by …
Browse files Browse the repository at this point in the history
…the Javassist transform.

It is not necessary to keep them in the ClassPool and detaching them can reduce memory consumption and avoid out of memory errors.
Note that this only affects users with AGP older than 4.2.0 since the HiltTransformTestClassesTask was replaced by the ASM pipeline.

Fixes: #2567
RELNOTES=Reduce the possibility of OOMs in the local unit test transform task that is executed for users with AGP older than 4.2.0.
PiperOrigin-RevId: 370120877
  • Loading branch information
danysantiago authored and Dagger Team committed Apr 23, 2021
1 parent 73f6458 commit 61ef9d8
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ internal class AndroidEntryPointClassTransformer(
if (entry.isClassFile()) {
val clazz = classPool.makeClass(input, false)
transformed = transformClassToOutput(clazz) || transformed
clazz.detach()
}
entry = input.nextEntry
}
Expand All @@ -99,7 +100,9 @@ internal class AndroidEntryPointClassTransformer(
"Invalid file, '$inputFile' is not a class."
}
val clazz = inputFile.inputStream().use { classPool.makeClass(it, false) }
return transformClassToOutput(clazz)
val transformed = transformClassToOutput(clazz)
clazz.detach()
return transformed
}

private fun transformClassToOutput(clazz: CtClass): Boolean {
Expand Down

0 comments on commit 61ef9d8

Please sign in to comment.