I read about avoiding memory leaks
to avoid context-related memory leaks, remember the following:
context-application
instead of a context-activity
And I have 2 questions :
setOnClickListener(this)
, will it cause a memory leak?setOnClickListener(new View.OnClickListener(){})
, will it cause a memory leak?1 - If I use setOnClickListener(this), will it cause a memory leak?
Not necessary, "this" implements OnClickListener and if you don't leak yourself... for example running a thread in onClick will leak, using a non static inner class will leak, so the answer is setOnClickListener(this) will leak only if your implementation of onClick(View view) leaks.
2 - If I use setOnClickListener(new View.OnClickListener(){}), will it cause a memory leak?
Is the same question, depends on what do you implement for OnClickListener.onClick... do not leak the class were you implement new View.OnclickListener.... and you will be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With