Android Studio说静态字段将泄漏上下文 [英] Android studio say static field will leak contexts
本文介绍了Android Studio说静态字段将泄漏上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此处是一个类似的问题,但我认为它不完全相同
Here is a similar question but I think it is not identical
我阅读了此处
在此页面中,他们编写了以下代码
In this page they write the following code
public class MySingleton {
private static Context mCtx;
我在项目中写了相同的代码
And I wrote same code in my project
public class VolleySingleton {
private static Context mContext;
Android Studio说不要将Android上下文类放在静态字段中;这是内存泄漏".
这是什么意思?为何Android官方开发人员网站使用这种代码?
Android studio say "Do not place Android context classes in static fields; this is a memory leak".
What does it mean? And why dos the official android developer website use such kind of code?
推荐答案
尝试这个吗? `
class VolleySingleton {
@SuppressLint("StaticFieldLeak")
private static Context mContext;
}`
这篇关于Android Studio说静态字段将泄漏上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文