React Native

Memory Management

Memory leaks, cleanup, useEffect cleanup, listeners, timers, large images handling

20 питань зі співбесід·
Senior
1

What is a memory leak in a React Native application?

Відповідь

A memory leak occurs when objects in memory are no longer used by the application but cannot be freed by the garbage collector because references to these objects still exist. In React Native, this commonly happens with uncleaned subscriptions, timers still active after unmount, or closures capturing stale references. Memory leaks gradually degrade performance and can cause crashes during long sessions.

2

What is the role of the return function (cleanup function) in useEffect for memory management?

Відповідь

The cleanup function returned by useEffect is executed before the component is unmounted or before the effect is re-executed with new dependencies. Its main role is to clean up resources allocated by the effect: cancel subscriptions, clearTimeout/clearInterval, remove event listeners, or abort pending requests. Without this cleanup, these resources continue to exist in memory and may attempt to update an unmounted component.

3

Why is it important to use clearTimeout and clearInterval in the useEffect cleanup function?

Відповідь

Timers created with setTimeout and setInterval continue to execute even after the component unmounts. If the timer callback attempts to update the state of an unmounted component, it triggers the warning 'Can't perform a React state update on an unmounted component' and constitutes a memory leak. The timer keeps a reference to the callback and its closure, preventing the garbage collector from freeing these resources. Using clearTimeout/clearInterval in cleanup ensures proper cancellation of these timers.

4

How to prevent memory leaks when using event listeners in React Native?

5

What is the impact of closures on memory management in React Native components?

+17 питань зі співбесід

Інші теми співбесід React Native

JavaScript Essentials

Junior
25 запитань

React Fundamentals

Junior
20 запитань

React Native Basics

Junior
22 запитань

React Hooks

Junior
20 запитань

TypeScript for React & React Native

Junior
22 запитань

React Native Components & API

Junior
20 запитань

React Native Styling & Layout

Junior
18 запитань

React Native Navigation

Mid-Level
22 запитань

React Native State Management

Mid-Level
24 запитань

React Native Networking & API

Mid-Level
20 запитань

Data Persistence

Mid-Level
20 запитань

Forms & Validation

Mid-Level
18 запитань

React Native Animations

Mid-Level
22 запитань

Native Modules & Bridge

Mid-Level
20 запитань

Platform-Specific Code

Mid-Level
18 запитань

Permissions & Device APIs

Mid-Level
20 запитань

Push Notifications

Mid-Level
18 запитань

React Native Testing

Mid-Level
20 запитань

React Native Debugging

Mid-Level
18 запитань

Build & Deployment

Mid-Level
20 запитань

Expo vs React Native Bare

Mid-Level
18 запитань

Performance Optimization

Senior
24 запитань

Architecture Patterns

Senior
22 запитань

React Native New Architecture

Senior
24 запитань

Security Best Practices

Senior
20 запитань

Offline-First Architecture

Senior
20 запитань

React Native CI/CD

Senior
20 запитань

Monorepo & Code Sharing

Senior
18 запитань

Advanced Topics

Senior
22 запитань

App Lifecycle & Background Execution

Mid-Level
20 запитань

Authentication & Session Management

Mid-Level
22 запитань

Monitoring & Crash Reporting

Senior
20 запитань

Опануй React Native для наступної співбесіди

Отримай доступ до всіх питань, flashcards, технічних тестів, вправ code review та симуляторів співбесід.

Почни безкоштовно