AceMobileInterview

Interview guides / ios

Leaky profile + secret logs: iOS Interview Question

Leaky profile + secret logs interview question with a clear example answer for iOS engineers. Practice with AceMobileInterview.

This is a common iOS interview topic: Leaky profile + secret logs.

Below is a concise answer you can adapt in a real interview, then go deeper in the full AceMobileInterview track.

  1. 1.Memory grows each time Profile is opened. Console also prints an access token. Find the retain cycle and unsafe logging (≈30–45 min).

    ## Scenario Profile screen leaks; security review flags tokens in logs. ## How to investigate - Debug Memory Graph / Allocations — filter `ProfileViewController` - Confirm `deinit` never prints - Grep for `print(` / `NSLog` / token fields ## Planted bug 1: Retain cycle in callback **Symptom:** VC count increases every push **Root cause:** `api.onProfile = { self.render($0) }` strong capture; `APIClient` owned by VC **Fix:** `{ [weak self] in self?.render($0) }`; break cycle in `deinit` / `viewDidDisappear` ## Planted bug 2: Timer / NotificationCenter not removed **Symptom:** Extra strong refs **Root cause:** `Timer.scheduledTimer` without `invalidate`; observer never removed **Fix:** Store timer, invalidate in `deinit`; use block-based observers carefully with weak self ## Planted bug 3: Logging secrets **Symptom:** Access token in console **Root cause:** `print("auth \(token)")` in `Session.store` **Fix:** Remove; if needed log only `token.prefix(4)` in DEBUG with a redaction helper—never full secrets ## Optimization tips - Prefer `[weak self]` as default in escaping closures owned by long-lived objects - Add a `deinit { print("Profile deinit") }` while debugging (remove later) ## What to say in the interview - How you confirmed the cycle in Memory Graph - Why logging tokens fails security review even in debug builds shipped to testers

Keep going with AceMobileInterview

Reading helps. Timed practice locks it in. Jump into the interactive track for algorithms with LeetCode links, studio projects, debugging zips, and mobile system design.

iOS trackAndroid trackMore guides