Skip to Content
Android Developer Tools深入精要
book

Android Developer Tools深入精要

by Mike Wolfson
July 2014
Intermediate to advanced
248 pages
5h 19m
Chinese
GoTop Information, Inc.
Content preview from Android Developer Tools深入精要
Android
中記憶體的使用情況
|
147
第十章:監控系統資源
第十章
監控系統資源
[Page-151]
因為行動裝置上的記憶體有限,所以監控資源的使用是很重要的;在這一章,我會介
紹如何使用分析工具瞭解應用程式的記憶體使用狀況。
Android
中記憶體的使用情況
Android
的開發者並不用像
C++
或其他語言一樣需要明確地分配記憶體,但這仍可能造
成「記憶體洩漏」(
memory leak
);因為程式將一個物件的參照保留住,因而導致一
大群物件無法被垃圾回收。這可能會是因為變數具不正確的有效範圍、在系統資源使
用過後沒有關閉控制數(
handle
)或是不會終止的處理程序所引起。
Dalvik runtime
具垃圾回收功能,這表示未使用的記憶體會在特定的時間間隔自動地被
系統回收;因為系統最終會做處理,這可能會讓你覺得可以完全地忽略記憶體的使用,
然而這並不正確,因為記憶體問題會透過許多不同的方式呈現,一些較明顯的方式如
未正確地回收
bitmap
而導致發生
OutOfMemory
例外。
有一些與記憶體相關的問題更難去除錯,且對效能的影響更顯著。這些問題是有關於
不易察覺且頻繁或大區塊的垃圾回收而導致的垃圾回收效能不佳,你的
app
不會因此
發生
OutOfMemory
例外而關閉程式,你的
app
會繼續執行,但效能降低且斷斷續續地
執行。垃圾回收對系統來說是很昂貴的操作,好的方式是在程式碼裡有效地管理記憶
體,則可以降低垃圾回收的頻率。
記憶體問題在
Android
中非常常見,你可能會在開發
Android
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Android 高效能多執行緒

Android 高效能多執行緒

Anders Goransson
深入淺出 jQuery

深入淺出 jQuery

Ryan Benedetti, Ronan Cranley
HTML5 錦囊妙計

HTML5 錦囊妙計

Christopher Schmitt, Kyle Simpson

Publisher Resources

ISBN: 9789863470861