Reputation: 193
In c# we must remove event subscribe, because if we lost link to object it will have memory leak. So need i remove listeners in java (ex.: remove listener from button on stop android activity) or it will be garbage collected?
mBtn.setOnClickListener(this); --> replace this by null on activity stop
Upvotes: 0
Views: 136
Reputation: 510
When the activity is closed the Objects no more referenced will be garbage collected. You don't need to do anything, that is why garbage collector is there in java, to free yourself from the memory allocation - deallocation mechanism.
Upvotes: 0
Reputation: 2844
I dont know what the stop-activitiy means but the listener will be eligible for the garbage collector as soon as there is no more reference that points to it. In other words if your programm ends on activity stop (sorry i dont know the live cycle) the mBtn reference will be eligible for the garbage collector and thatfore the listener as well while you would have to set it to null according the above part of your question if you just want to remove the listener (and have a dead button or apply another listener to it) and eligible it (the listener) for garbage collection.
Upvotes: 1