InterviewStack.io LogoInterviewStack.io

Mobile Memory and Resource Management Questions

Covers memory management principles and resource handling for mobile applications across platforms. Candidates should understand platform specific models such as automatic reference counting on iOS and garbage collection on Android, common causes of memory leaks and retain cycles, and how reference ownership and weak versus strong references affect lifetime. Include techniques for releasing resources correctly in lifecycle methods and avoiding long lived references that hold activity or context objects. Expect knowledge of memory profiling and diagnostics including tools and workflows for locating leaks and high memory usage, strategies to prevent out of memory conditions, and trade offs such as requesting a larger heap. Also cover cross platform considerations for frameworks like React Native and Flutter and practical practices for identifying and fixing real memory issues in production, such as analyzing heap dumps, using allocation instrumentation, and applying targeted fixes and regression tests.

HardTechnical
0 practiced
Describe how you would detect and fix native (C/C++) memory leaks in a mobile app that uses JNI or custom native libraries. Include tools and techniques you would use on Android (Address Sanitizer, Native Memory Profiler, special build flags) and iOS (Xcode Instruments, Address Sanitizer), how to reproduce leaks, interpret leak reports, and remediation strategies such as RAII, smart pointers, and explicit lifecycle-based frees.
MediumTechnical
0 practiced
Refactor the Swift code below to avoid a retain cycle without leaking, and explain why your solution is safe.
class MyViewController: UIViewController {
    var loader: NetworkLoader?
    override func viewDidLoad() {
        super.viewDidLoad()
        loader?.load { data in
            self.updateUI(with: data)
        }
    }
    func updateUI(with data: Data) { /* update views */ }
}
Show at least two valid refactorings (capture list or alternate ownership) and explain lifetime implications.
HardTechnical
0 practiced
As a senior engineer, create a plan to set memory budgets, developer guidelines, and automated checks across multiple mobile teams. Describe the process to define device-class budgets, implement CI checks for memory regressions, provide training and shared tooling, create dashboards for visibility, and a process for exceptions or justifying larger budgets. Include stakeholder coordination with product and QA.
MediumTechnical
0 practiced
A native module in a React Native Android app retains JS callbacks and causes memory to grow. Describe code-level fixes on both Android (Java/Kotlin) and iOS (Objective-C/Swift) to avoid retaining Activity/View references across callbacks. Include patterns for explicitly releasing callbacks, using weak references, and ensuring callbacks are invoked or cleared when the host is destroyed.
EasyTechnical
0 practiced
Given the Android Activity code below, identify why it can leak memory and describe at least two code fixes.
java
public class MainActivity extends Activity {
    private final Handler handler = new Handler();
    @Override protected void onCreate(Bundle b) {
        super.onCreate(b);
        handler.postDelayed(new Runnable() {
            @Override public void run() {
                doHeavyWork(); // implicitly references MainActivity
            }
        }, 60000);
    }
}
Explain the leak cause and show code-level corrections (for example static handler pattern, weak references, or removing callbacks).

Unlock Full Question Bank

Get access to hundreds of Mobile Memory and Resource Management interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.