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

middle

What is an Android PendingIntent ?

expert

What happens if the user navigates away or closes the app while I still have a reference to the Activity
the user just closed in my AsyncTask ?

entry

What is the difference between Bitmap and Drawable in Android?

Bình luận

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

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