You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class IMusicServiceStub extends IMusicService.Stub {
private static final String TAG = "IMusicServiceStub";
private final WeakReference mService;
public class IMusicServiceStub extends IMusicService.Stub {
private static final String TAG = "IMusicServiceStub";
private final WeakReference mService;
作者,你好,这里的mService弱引用,好像并不能被gc回收,我在MainActivity,写了计时器,没三秒触发一次GC,但是这个mService hashcode一直没有变过,是否这个弱引用无效呢?
不停触发GC
private Handler handler = new Handler() {
@OverRide
public void handleMessage(Message msg) {
super.handleMessage(msg);
LogUtil.e(TAG, "触发GC");
handler.sendEmptyMessageDelayed(1, 3000);
System.gc();
}
};
由于对弱引用不太了解,所以想问下,弱引用在使用过程中被GC回收了,该怎么办,重新生成弱引用对象吗?
希望解惑,谢谢。
2020-05-22 10:32:42.426 22107-22107/com.cyl.musiclake E/IMusicServiceStub: HashCode=98214344
2020-05-22 10:32:43.346 22107-22107/com.cyl.musiclake E/MainActivity: 触发GC
2020-05-22 10:32:46.356 22107-22107/com.cyl.musiclake E/MainActivity: 触发GC
2020-05-22 10:32:49.221 22107-22107/com.cyl.musiclake E/IMusicServiceStub: HashCode=98214344
2020-05-22 10:32:49.377 22107-22107/com.cyl.musiclake E/MainActivity: 触发GC
2020-05-22 10:32:50.855 22107-22107/com.cyl.musiclake E/IMusicServiceStub: HashCode=98214344
2020-05-22 10:32:52.383 22107-22107/com.cyl.musiclake E/MainActivity: 触发GC
2020-05-22 10:32:53.146 22107-22107/com.cyl.musiclake E/IMusicServiceStub: HashCode=98214344
2020-05-22 10:32:54.384 22107-22107/com.cyl.musiclake E/IMusicServiceStub: HashCode=98214344
2020-05-22 10:32:55.413 22107-22107/com.cyl.musiclake E/MainActivity: 触发GC
2020-05-22 10:32:56.875 22107-22107/com.cyl.musiclake E/IMusicServiceStub: HashCode=98214344
2020-05-22 10:32:58.131 22107-22107/com.cyl.musiclake E/IMusicServiceStub: HashCode=98214344
The text was updated successfully, but these errors were encountered: