从碎片中释放记忆

时间:2018-04-30 11:28:51

标签: java android android-memory

我想知道片段被销毁后存在于片段内的变量/对象会发生什么。例如,FloatingActionButton是一个留在片段内的实例。当片段被破坏时,FloatingActionButton也是吗?还是我需要自己释放记忆?另外,完成方法就被破坏了,我需要调用吗?

public class Hello extends Fragment {

private final Fragment fragment = this;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    return inflater.inflate(R.layout.content_main, container, false);
}

@Override
public void onStart() {
    FloatingActionButton fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {


    });
    super.onStart();
}



@Override
public void onDestroy() {
    Log.d("ButtonScan","Destroyed");
    try {
        finalize();
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }
    super.onDestroy();
}
}

0 个答案:

没有答案