Code RoomView model leak on refresh
MediumPrep Room Coding #4199

View model leak on refresh

Vibe & agenticAlgorithms & data structuresMid–Senior~16 min

An AI assistant wrote this SwiftUI view-model networking helper. It compiles and works in a quick demo, but in a long-lived screen that re-fetches on pull-to-refresh, instruments shows the view-model count climbing and never dropping. Identify the leak and how you'd catch it.

Implement
simulate_view_model_leak(lifecycle_events: list[str], weak_capture: bool, invalidate_on_disappear: bool) → list[int]
Examples
in[["appear","disappear","appear","disappear","appear","disappear"],false,false]out[3,3]
in[["appear","disappear","appear","disappear","appear","disappear"],false,true]out[0,0]
What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it (tests, edge cases, reading critically), and how you’d re-prompt or decompose to get it right.

0:00 of about 16 min

Vibe & agentic: describe the solution in plain language (or narrate it) and the coach grades your approach.

Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.