我在 onCreateView 中声明了一个静态 Fragment 变量,如下所示:
public static Fragment instance;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState){
instance = this;
}
我知道这会导致内存泄漏,所以我需要正确释放实例变量(instance=null)。只是想知道我应该在哪里发布它。就像在 onPause 或 onDestroyView 或其他覆盖方法中一样?