-
Notifications
You must be signed in to change notification settings - Fork 0
/
27 高级提升
30 lines (26 loc) · 2.19 KB
/
27 高级提升
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
27.高级提升
一、内存泄露(体会总结)
内存泄露的概念含义:一个已无用对象仍被其他对象所持有,无法被系统回收造成空间浪费。就叫内存泄露。
常见内存泄露场景概括:
1.对象引用了外部其他对象,然后被应用对象生命周期先死,该对象还保存着,那么就可能导致内存泄露。
比如:引用别人(activity)的context, 控件View, Handle创建默认引用了activity。所以引用对象要保证比被引用方(activity)更早被回收,如果无法保证建议弱引用。
如果是单例或者静态对象那么 使用到引用对象就必须考虑释放使用问题,保证提前于别引用方释放,没法保证用弱引用。
土话:借用了别人对象,就可能别人死了,你还负债在身。
常有特点:对象是单例、静态对象、长生命周期对象。
被引用常有:1.(activity中获得)context 2.(activity中的)View 3.(activity中实例化的)Handler 4.对象内线程(不及时和activity死去) 5.未注销注册和回调
比如引用了context view 和Handle实例化就绝对有嫌疑了,如果是静态或单例对象引用没有对应提前规范释放引用的就绝逼是会泄露了。
二、观察者模式使用 RxJava+Retrofit
//定义接口
//interface AnchorApiSevice {
// @GET("News/{userId}")
// Call<TradesBean> getItem(@Path("userId") String userId); //简单单参数get请求
// @GET("search")
// Observable<SearchResult> searchLyric(@QueryMap Map<String, Object> params);//简单多参数get请求
//@POST("mv/trial")
//Observable<Response<MvUrl>> getMvUrlAnonymous(@Header("signature") String signature, @Header("signtrial") String signtrial, @Body Map<String, Object> params);
//分块上传初始化
//@POST("/multipart/initiate")
//Observable<Response<UploadInitResult>> initUpload(@HeaderMap Map<String, String> heardParams, @QueryMap Map<String, Object> params);
//分块上传文件内容
//@POST("/multipart/upload")
//Observable<Response<UploadPartResult>> upload(@HeaderMap Map<String, Object> heardParams, @QueryMap Map<String, Object> params, @Body RequestBody requestBody);