Memory Leaks and Xamarin

Hi!

Long time lurker first time posting, nice to meet you all!

I want to discuss a bit about the subject of memory leaks in xamarin. I have researched the subject quite a bit but i am still kinda unsure what is the correct way to handle memory leaks. To demonstrate what i want to discuss in fact you should just create an empty android project (not forms). Then in the button click instead of hello world make it navigate to another activity (even an exact one like main activity). If you enable StrictMode and make the navigation a few times you will see that the activity leaks even with subscribing to button's click with a delegate and unsubscribing later. The only way i have found that it will work is to keep a reference of the button and dispose it in on destroy. So the first scale of my question is: should i dispose every view that i find by id?

Alas, i have done the exact same thing on a company project that i work on and there are some things that made me curious. Sometimes not only do i need to dispose the views that i found by id, but also views like card view or circle page indicator even if i didn't save a reference to it, nor did i use it for a click event or something similar. Is this normal behavior?

Last but not least, sorry for the long post but seriously i am at a dead's end here about some things.. Classes like google api client that take the context as an argument also leak! Am i going insane or am i misinterpreting strict mode log's that there are two instances of my activity?

Thanks in advance for everyone that will answer!

Tagged:
Sign In or Register to comment.