Kapt: Support paranoid mode in memory leak searcher

This commit is contained in:
Yan Zhulanow
2018-11-06 15:35:38 +09:00
parent ecc44419b6
commit 9feb834d97
2 changed files with 4 additions and 3 deletions
@@ -51,7 +51,7 @@ object MemoryLeakDetector {
}
}
fun process(): Set<MemoryLeak> {
fun process(isParanoid: Boolean): Set<MemoryLeak> {
val memoryLeaks = mutableSetOf<MemoryLeak>()
synchronized(classLoaderData) {
@@ -60,7 +60,7 @@ object MemoryLeakDetector {
val classLoader = data.ref.get() ?: continue
data.age += 1
if (data.age >= 5) {
if (isParanoid || data.age >= 5) {
// Inspect statics just once.
// Note the 'data' is not added to 'nextClassLoaderData' used the next time.
inspectStatics(classLoader)
@@ -228,7 +228,8 @@ abstract class AbstractKapt3Extension(
if (options.detectMemoryLeaks != DetectMemoryLeaksMode.NONE) {
MemoryLeakDetector.add(processors.classLoader)
val (leakDetectionTime, leaks) = measureTimeMillis { MemoryLeakDetector.process() }
val isParanoid = options.detectMemoryLeaks == DetectMemoryLeaksMode.PARANOID
val (leakDetectionTime, leaks) = measureTimeMillis { MemoryLeakDetector.process(isParanoid) }
logger.info { "Leak detection took $leakDetectionTime ms" }
for (leak in leaks) {