A ViewModel launches `viewModelScope.launch { val a = async { fetchA() }; val b = async { fetchB() }; combine(a.await(), b.await()) }`. `fetchB()` throws. What happens?
- A. Only `b.await()` throws; `a` keeps running and the parent coroutine survives, logging the error
- B. The exception from `fetchB()` propagates, cancels the parent coroutine (and sibling `a`), and crashes unless a handler is installed on the scope ✓
- C. `async` swallows the exception until `a.await()` is also called, so nothing happens
- D. A `CoroutineExceptionHandler` on `async` catches it and resumes normally
Correct answer: B. Because these `async` builders inherit the regular `Job` of `viewModelScope`, a child failure propagates upward, cancelling the parent and sibling regardless of when `await()` is called.
A Compose list item recomposes on every scroll frame even when its data is unchanged. The item takes `List<Item>` and a `() -> Unit` lambda as parameters. What is the MOST likely root cause and fix?
- A. `List<Item>` is inferred unstable, so the composable is never skippable; use `ImmutableList`/`@Immutable` or `kotlinx.collections.immutable` ✓
- B. The lambda allocates each recomposition; wrapping it in `remember` fixes stability of the list too
- C. `derivedStateOf` must wrap the list read to make it observable and skippable
- D. Marking the item `@Composable @Stable` forces Compose to skip regardless of parameter stability
Correct answer: A. The Compose compiler treats `List` as unstable (it could be a mutable implementation), making the function non-skippable; using a provably-immutable collection type restores skippability.
You call `stateFlow.collect { }` inside a `Fragment.onViewCreated` using `lifecycleScope.launch { ... }` (not `repeatOnLifecycle`). What is the concrete bug?
- A. Collection stops at `onStop` and correctly restarts at `onStart`, so it is safe
- B. StateFlow is cold, so nothing is ever collected without `repeatOnLifecycle`
- C. The coroutine keeps collecting while the Fragment is in the background and holds the destroyed View, wasting work and risking a leak ✓
- D. `StateFlow` conflates emissions, so background collection is automatically paused
Correct answer: C. `lifecycleScope.launch` only cancels at `onDestroy`, so the collector stays active in the background updating a stopped/destroyed view; `repeatOnLifecycle(STARTED)` is what pauses and resumes it.
Two offline devices edit the same record's different fields while disconnected, then both sync. The backend must remain single source of truth and no user edit should be silently lost. Which strategy best satisfies this?
- A. Last-write-wins by wall-clock timestamp on the whole record
- B. Per-field merge / CRDT-style reconciliation on the server so non-conflicting field edits both survive ✓
- C. Reject the later sync with a 409 and force the user to re-enter everything
- D. Vector clocks that only detect conflicts but always discard the older sibling
Correct answer: B. Whole-record LWW loses one device's field edit; per-field (or CRDT) merge lets independent field changes coexist while the server stays authoritative for true conflicts.
In Swift, a `URLSession` completion closure captures `self` and stores the returned task in a `self.task` property. Even after the request finishes, the object leaks. Why, and what is the minimal fix?
- A. `URLSession` is a singleton so it always retains delegates; switch to `.shared`
- B. The closure strongly captures `self` while `self` retains the task via `self.task`, forming a retain cycle; use `[weak self]` in the capture list ✓
- C. ARC cannot free `URLSessionTask`; call `task.cancel()` in `deinit`
- D. Completion closures are always `@escaping` and leak by design; mark it non-escaping
Correct answer: B. `self` → `task` → closure → `self` is a strong reference cycle; capturing `[weak self]` breaks it so ARC can deallocate once the request completes.
Under Swift 6 strict concurrency, you have a mutable cache accessed from many `Task`s. Which primitive gives compile-time data-race safety with the least boilerplate?
- A. A `class` guarded by a manual `NSLock` around every access
- B. An `actor` wrapping the cache, so all mutable access is serialized and isolated ✓
- C. A `DispatchQueue.sync` barrier on a concurrent queue
- D. Marking the cache `@unchecked Sendable` and hoping callers serialize
Correct answer: B. An `actor` provides compiler-enforced isolation and serialized access to its mutable state, which is exactly what strict concurrency checking rewards, without manual locking.
A React Native (old architecture) screen janks when a native module returns a large payload consumed on scroll. Why does JSI/TurboModules fix it where the legacy bridge could not?
- A. JSI adds more worker threads to the bridge queue so serialization is parallelized
- B. The legacy bridge serializes all calls to JSON and batches them async over a single queue; JSI lets JS hold direct synchronous references to native objects, removing the serialization bottleneck ✓
- C. TurboModules move all JS execution onto the UI thread, eliminating frame drops
- D. Fabric compresses the JSON payload so it crosses the bridge faster
Correct answer: B. The old bridge's cost is asynchronous JSON serialization over one queue; JSI exposes native objects to the JS engine directly (synchronously, no JSON), which TurboModules/Fabric build on to remove that bottleneck.
An Android app is killed under memory pressure while a form is half-filled. On relaunch the user lands back with an empty form. `onSaveInstanceState` was implemented but data still lost. Which is the correct explanation?
- A. `onSaveInstanceState` is only for config changes; process death also needs the saved Bundle to be restored in `onCreate`/`SavedStateHandle`, and large data exceeding Binder limits is dropped ✓
- B. Process death never triggers `onSaveInstanceState`, so no state can ever be saved
- C. `ViewModel` survives process death and should have held the form state
- D. Restoration fails because `onRestoreInstanceState` runs before `onCreate`
Correct answer: A. `onSaveInstanceState` does fire before process death, but restored state must be read back (via Bundle/SavedStateHandle) and stay within the ~1MB Binder transaction limit or it is silently dropped; ViewModels do NOT survive process death.
A coroutine wrapped in `withContext(NonCancellable)` or doing a tight CPU loop `while(true){}` ignores `job.cancel()`. Why doesn't it stop, and what is the correct fix for the CPU-loop case?
- A. Cancellation is cooperative; a busy loop never suspends or checks `isActive`, so add `ensureActive()`/`yield()` or check `isActive` in the loop ✓
- B. `cancel()` only sets a flag for structured concurrency and never affects running code
- C. Dispatchers.Default disables cancellation for performance
- D. The loop needs `SupervisorJob` to become cancellable
Correct answer: A. Coroutine cancellation is cooperative and only takes effect at suspension/check points, so a non-suspending busy loop must explicitly call `yield()`/`ensureActive()` or test `isActive`.
You want a `Flow` that (a) has no initial value, (b) never replays to new subscribers, and (c) drops events if there are momentarily no collectors, for one-shot navigation events. Which construct fits?
- A. `StateFlow` with an initial dummy value
- B. `SharedFlow(replay = 0, extraBufferCapacity = 0, onBufferOverflow = SUSPEND)` — with an active collector, or `Channel` for strict single-consumer delivery ✓
- C. `StateFlow(null)` mapped with `filterNotNull`
- D. `SharedFlow(replay = 1)`
Correct answer: B. `replay = 0` prevents redelivery to late subscribers (StateFlow always replays its latest), matching one-shot event semantics; a `Channel` is the stricter single-consumer alternative.
In Swift ARC, which reference declaration breaks a strong reference cycle while safely becoming nil when the referent is deallocated?
- A. strong
- B. weak ✓
- C. unowned with a non-optional
- D. static
Correct answer: B. A weak reference does not increase the retain count and is automatically set to nil when the referent is deallocated, breaking cycles safely.
In the React Native New Architecture, what does Fabric primarily replace and improve?
- A. The Metro bundler
- B. The legacy UIManager rendering system, enabling synchronous, concurrent rendering ✓
- C. The JavaScript engine only
- D. The npm dependency resolver
Correct answer: B. Fabric is the new rendering system replacing the old UIManager, allowing synchronous layout and better concurrency via a C++ shadow tree.
In Android, why can a memory leak occur when a non-static inner class or long-lived callback holds a reference to an Activity?
- A. Inner classes cannot access the outer class
- B. The implicit reference to the Activity prevents it from being garbage-collected after it is destroyed ✓
- C. The Activity is duplicated in memory automatically
- D. Static classes always leak more than inner classes
Correct answer: B. A non-static inner class holds an implicit reference to its outer Activity; if a long-lived object retains it, the destroyed Activity can't be collected.
In Kotlin coroutines, what structured-concurrency guarantee does coroutineScope provide over launching in GlobalScope?
- A. It runs all work on the IO dispatcher
- B. It waits for all child coroutines and cancels siblings if one fails, tying lifetimes to the scope ✓
- C. It never propagates exceptions
- D. It disables cancellation entirely
Correct answer: B. coroutineScope enforces structured concurrency: it suspends until children complete and cancels remaining children if one throws, unlike leak-prone GlobalScope.
In iOS, why is dispatching a UIKit view update from a background thread problematic?
- A. UIKit updates are thread-safe everywhere
- B. UIKit is not thread-safe and UI updates must occur on the main thread, or you risk undefined behavior and crashes ✓
- C. Background threads run faster and skip rendering
- D. It only affects SwiftUI, not UIKit
Correct answer: B. UIKit is main-thread-confined; updating UI off the main thread causes race conditions, glitches, or crashes.
In Flutter, what is the purpose of a 'const' constructor on a widget for rendering performance?
- A. It makes the widget mutable at runtime
- B. It lets the framework canonicalize and reuse the widget instance, skipping unnecessary rebuilds ✓
- C. It forces a full repaint every frame
- D. It disables the widget's build method
Correct answer: B. const widgets are compile-time constants that Flutter can reuse and short-circuit during rebuilds, reducing widget tree churn.
When implementing certificate pinning to prevent MITM attacks, what is a critical operational risk to plan for?
- A. It makes the app load faster than needed
- B. Pinned certificates expire or rotate, which can break connectivity if the app isn't updated in time ✓
- C. It permanently disables HTTPS
- D. It only works on emulators
Correct answer: B. Pinning ties the app to specific certs/keys; when the server rotates certificates, un-updated apps lose connectivity, requiring backup pins and an update strategy.
On Android, what is the primary benefit of using an App Bundle (.aab) over a universal APK for Play Store distribution?
- A. It encrypts all source code automatically
- B. Google Play generates optimized, smaller APKs tailored to each device's density, ABI, and language ✓
- C. It removes the need for signing
- D. It disables Play Store review
Correct answer: B. The App Bundle lets Play's Dynamic Delivery serve device-specific split APKs, reducing download size versus a fat universal APK.
In SwiftUI, what does the @State property wrapper fundamentally provide for a view?
- A. A globally shared singleton
- B. A view-owned source of truth that triggers a re-render when its value changes ✓
- C. Persistent disk storage across launches
- D. A background thread executor
Correct answer: B. @State gives a view local, mutable state managed by SwiftUI; mutating it invalidates and re-renders the view body.
Why does frequent high-accuracy GPS most heavily impact battery, and what mitigates it?
- A. GPS uses no power; the screen is the only drain
- B. Continuous GPS keeps a power-hungry radio active; using lower accuracy, geofencing, or fused/batched location reduces drain ✓
- C. Battery drain comes only from the CPU, not sensors
- D. Disabling the network fully solves GPS drain
Correct answer: B. Continuous high-accuracy GPS keeps the power-intensive GNSS radio on; fused/low-power modes, geofencing, and batching cut battery use significantly.
In Android, transient UI state that must survive the process being killed for memory is best restored via...
- A. onDestroy only
- B. onSaveInstanceState / SavedStateHandle ✓
- C. Static variables
- D. The manifest file
Correct answer: B. The saved-state bundle (SavedStateHandle) persists small UI state across process death.
Swift's ARC frees an object when...
- A. Its strong reference count reaches zero ✓
- B. The app is closed
- C. A garbage collector runs
- D. A memory warning is fired
Correct answer: A. Swift has no GC; ARC deallocates an object the moment its strong count hits zero.
Flutter maintains three parallel trees named...
- A. Widget, State, and Layout trees
- B. DOM, Virtual DOM, and Render trees
- C. Widget, Element, and RenderObject trees ✓
- D. View, Model, and Controller trees
Correct answer: C. Widgets configure Elements, which manage RenderObjects that handle layout and painting.
React Native's new architecture replaces the async bridge with...
- A. JSI enabling synchronous native calls (with Fabric/TurboModules) ✓
- B. An embedded WebView
- C. A Dart virtual machine
- D. A Redux store
Correct answer: A. The JavaScript Interface (JSI) lets JS invoke native code synchronously, powering Fabric and TurboModules.
A common Android memory leak results from...
- A. Using a ViewModel
- B. Recycling views in a RecyclerView
- C. Using structured coroutines
- D. A static/long-lived object holding an Activity or Context reference ✓
Correct answer: D. A long-lived reference to an Activity prevents it from being garbage collected, leaking memory.
In iOS, capturing self strongly inside an escaping closure risks a retain cycle; the fix is...
- A. A [strong self] capture
- B. A [weak self] capture list ✓
- C. Calling DispatchQueue.main.async
- D. Force-unwrapping self
Correct answer: B. A [weak self] capture avoids the closure retaining self and creating a cycle.
Flutter's const constructors improve performance because...
- A. They run on the GPU
- B. They compile to native machine code
- C. Identical const widgets are canonicalized and skip rebuild/reallocation ✓
- D. They cache network responses
Correct answer: C. const widgets are compile-time constants reused across builds, avoiding rebuild work.
To render at 60fps, each frame must be produced within roughly...
- A. 16.67 ms ✓
- B. 100 ms
- C. 1 second
- D. 33 ms
Correct answer: A. 1000 ms divided by 60 frames is about 16.67 ms per frame.
In Android, coroutine work tied to a ViewModel should use ___ so it cancels when the ViewModel is cleared.
- A. GlobalScope
- B. viewModelScope ✓
- C. A raw Thread
- D. The Activity's lifecycleScope
Correct answer: B. viewModelScope is automatically cancelled in onCleared, preventing leaks.
iOS's Main Thread Checker flags UIKit calls made off the main thread because UIKit is...
- A. Too slow when run in the background
- B. GPU-bound and cannot use threads
- C. Deprecated in modern iOS
- D. Not thread-safe and must be updated on the main thread ✓
Correct answer: D. UIKit is not thread-safe, so all UI updates must occur on the main thread.