Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMusicServiceStub弱引用service #79

Open
MoYuFly opened this issue May 22, 2020 · 0 comments
Open

IMusicServiceStub弱引用service #79

MoYuFly opened this issue May 22, 2020 · 0 comments

Comments

@MoYuFly
Copy link

MoYuFly commented May 22, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant