Skip to content

Commit

Permalink
Benchmarks: fix OOM crash on a real iOS device. Part 2. (#5211)
Browse files Browse the repository at this point in the history
- add memory warning monitor to do explicit GC

## Release Notes
N/A
  • Loading branch information
pjBooms authored Jan 27, 2025
1 parent cedd48f commit aeddeba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,6 @@ suspend fun measureComposable(
)
} finally {
scene.close()
runGC() // cleanup for next benchmarks
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/

import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch

fun main(args : List<String>) {
Args.parseArgs(args.toTypedArray())
runBlocking { runBenchmarks(graphicsContext = graphicsContext()) }
MainScope().launch {
runBenchmarks(graphicsContext = graphicsContext())
println("Completed!")
}
}
19 changes: 19 additions & 0 deletions benchmarks/multiplatform/iosApp/iosApp/iOSApp.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import SwiftUI
import benchmarks
import Combine

class MemoryWarningMonitor: ObservableObject {
private var cancellable: AnyCancellable?

init() {
self.cancellable = NotificationCenter.default
.publisher(for: UIApplication.didReceiveMemoryWarningNotification)
.sink { _ in
self.didReceiveMemoryWarning()
}
}

private func didReceiveMemoryWarning() {
// print("Memory warning received! Cleaning resources.")
RunGC_nativeKt.runGC()
}
}

@main
struct iOSApp: App {
init() {
MemoryWarningMonitor()
Main_iosKt.main(args: ProcessInfo.processInfo.arguments)
}

Expand Down

0 comments on commit aeddeba

Please sign in to comment.