About Cacher
Web App
Download
Sign In
Sign Up
menu
Cacher is the code snippet organizer for pro developers
We empower you and your team to get more done, faster
Learn More
smilevchy
3/20/2016 - 1:23 PM
share
Share
add_circle_outline
Save
About context.md
illustration.jpg
content_copy
file_download
Rendered
Source
About context.md
content_copy
file_download
Rendered
Source
使用 Activity 或其他非 Application 级实例 作为 context 使用时,需要注意避免内存泄露问题(比如将 Activity 实例传递给某个生命周期更长的对象如静态类实例并被强引用,该 Activity 实例将不会被回收,造成内存泄漏)
跟UI相关的,都应该使用Activity做为Context来处理
应用程序创建Context实例的情况有如下几种情况:a. 创建Application 对象时, 而且整个App共一个Application对象; b. 创建Service对象时; c. 创建Activity对象时
总Context实例个数 = Service个数 + Activity个数 + 1(Application对应的Context实例)
clear