Câu hỏi phỏng vấn Android
Câu hỏi

How does the OutOfMemory happens?

Câu trả lời

Here is a detailed answer to the Android interview question "How does OutOfMemoryError happen?":

OutOfMemoryError in Android

An OutOfMemoryError (OOM) occurs when the Android app tries to allocate more memory than is available to the app's process. This can happen for a few key reasons:

1. Bitmap Handling

Bitmaps are a common cause of OOMs. Loading large bitmaps into memory without properly scaling or sampling them can easily exceed the available heap size. Bitmaps should be loaded and scaled to the exact size needed to avoid wasting memory.

2. Leaking Activities or Views

If an Activity or View has a reference to a large object that is not properly cleared when the Activity or View is destroyed, it can cause a memory leak. This leads to the objects staying in memory longer than needed, eventually causing an OOM.

3. Inefficient Data Structures

Using inefficient data structures like ArrayLists or HashMaps to store large amounts of data can lead to OOMs. Prefer using more ...

junior

junior

Gợi ý câu hỏi phỏng vấn

expert

What is Intent vs Sticky Intent vs Pending Intent ?

senior

Why to consider FlatBuffers over JSON ?

senior

What is the difference between Android Timer and a Handler to do action every N seconds?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào