Forum Cross Platform with Xamarin

Life cycle of background thread's methods variables used in UI thread

I am wondering how the background thread's (tasks) method variable are garbage collected when they are still used in UI thread which is called within same method. Do we need to free them manually?

For example I launch a background task where I get some array of data from rest service and store it in a method variable. Then in same background task's method I invoke the UI thread and use the background created data to manipulate bindable UI array. Would it be good idea now to free up the data array which was created in background thread? or it will garbage collected efficiently?


  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    The short answer is: If they are still in use they won't be subject to GC - the thread upon which they are created (UI in this case) won't affect that.

    Garbage Collection across Xamarin is a tad complex because it happens in two layers. .NET will want to do GC, but that passes down to the platform. So .NET will have its stages of use and when it finally clears something for collection it still has to be cleared by the Android GC system.

Sign In or Register to comment.