Tencent/matrix · error · IllegalStateException
Matrix is NOT installed or MemoryInfoFactory is not…
Error message
Matrix is NOT installed or MemoryInfoFactory is not initialized!!!
What it means
MemInfoFactory reads memory stats through an ActivityManager obtained either from a manually provided Application or from Matrix.with().application. Its init block throws IllegalStateException when neither manual initialization happened nor Matrix is installed, because there is no Application context to resolve ActivityManager from.
Solutions
- Install Matrix first: Matrix.with().install(this) in Application.onCreate before any MemInfoFactory usage.
- Alternatively call MemInfoFactory.manualInit(application) if you want memory stats without full Matrix install.
- Gate memory-stat collection behind Matrix.isInstalled() checks and skip when not installed.
- In non-Matrix contexts, construct the ActivityManager from your own context instead of MemInfoFactory.
Example fix
// before
val pss = MemInfoFactory.getPss()
// after
if (Matrix.isInstalled()) {
val pss = MemInfoFactory.getPss()
} else {
MemInfoFactory.manualInit(application)
val pss = MemInfoFactory.getPss()
} Defensive patterns
Strategy: validation
Validate before calling
if (!Matrix.isInstalled()) {
MemInfoFactory.manualInit(application)
}
val pss = MemInfoFactory.getPss() Type guard
fun memInfoReady(): Boolean = Matrix.isInstalled()
fun getPssSafe(): Long =
if (memInfoReady()) MemInfoFactory.getPss() else -1L Try / catch
val pss = try {
MemInfoFactory.getPss()
} catch (e: IllegalStateException) {
MatrixLog.w(TAG, "MemInfoFactory not initialized", e)
-1L
} Prevention
- Install Matrix in Application.onCreate before any memory-stat collection.
- Use manualInit(application) in processes or tests where Matrix is not installed.
- Gate stats collection behind Matrix.isInstalled() in shared utility code.
When it happens
Trigger: Instantiating or using MemInfoFactory (or its default instance) when Matrix.with() was never called (Matrix.install not run) and MemInfoFactory.manualInit(app) was not invoked beforehand.
Common situations: Using memory-stat utilities in a unit test or a process where Matrix was never installed; calling MemInfoFactory before Matrix.with().install(this) in Application.onCreate; disabling Matrix in debug builds while stats code still runs.
Related errors
- sBuffer == null
- NOT initialized yet
- NOT initialized yet
- Supervisor NOT initialized yet or Supervisor is disabled!!!
- not initialized yet !
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/087c62de4c320ed1.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/util/MemInfoFactory.kt:39
*/
object MemInfoFactory {
@Volatile
@JvmStatic
private var manualInitialized = false
@Volatile
@JvmStatic
private var application: Application? = null
@JvmStatic
fun init(app: Application) {
application = app
manualInitialized = true
}
init {
if (!manualInitialized && !Matrix.isInstalled()) {
throw IllegalStateException("Matrix is NOT installed or MemoryInfoFactory is not initialized!!!")
}
}
val activityManager = (if (manualInitialized) application else Matrix.with().application)
?.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val memClass = activityManager.memoryClass
val largeMemClass = activityManager.largeMemoryClass
}
data class ProcessInfo(
val pid: Int = Process.myPid(),
val name: String = MatrixUtil.getProcessName(Matrix.with().application),
val activity: String = ProcessUILifecycleOwner.recentScene.substringAfterLast('.'),
val isProcessFg: Boolean = ProcessUIStartedStateOwner.active(),
val isAppFg: Boolean = ProcessSupervisor.isAppUIForeground
) : Parcelable {
constructor(parcel: Parcel) : this(View on GitHub (pinned to 3b8293bd65)