I've scoured Google and forums for a few hours now with no luck. I'm having an issue with programmatically generated layouts and garbage collection.
My app loads information from a sqlite database and generates a form based on what's handed to it. I.e. if question type is "ComboPicker" then create a new spinner and add it to the view.
Here's an example for NumericEntry:
case "NumericEntry":
EditText numericField = new EditText (Activity);
numericField.SetRawInputType (InputTypes.ClassNumber);
LinearLayout.LayoutParams numericParams = new LinearLayout.LayoutParams (LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.WrapContent);
numericParams.Weight = 1.0F;
numericField.LayoutParameters = numericParams;
Activity.RunOnUiThread(() => sectionLayout.AddView (numericField))); //Has to be run on the activity thread since it's being run on a background thread. sectionLayout is the parent view
break;
So this loads up all well and good, and I put it on the background thread so it keeps responsiveness when loading, but the problem is when I leave this fragment. The garbage collector becomes very unhappy and pauses the app while it collects the this can hang up the app for 2 seconds which is undesirable.
[Mono] GC_BRIDGE num-objects 1464 num_hash_entries 3184 sccs size 3184 init 0.00ms df1 14.80ms sort 3.69ms dfs2 5.98ms setup-cb 2.41ms free-data 3.97ms user-cb 156.78ms clenanup 3.72ms links 2845/2845/5014/40 dfs passes 7493/6029
[Mono] GC_MINOR: (Nursery full) pause 60.37ms, total 61.04ms, bridge 176.74ms promoted 816K major 1120K los 72K
[Choreographer] Skipped 35 frames! The application may be doing too much work on its main thread.
[Choreographer] Skipped 147 frames! The application may be doing too much work on its main thread.
I've tried forcing garbage collections after the form is populated, after the fragment is paused, and everywhere in between and it still hangs when I change fragments to something else. I'm obviously doing something very wrong, but I'm at a loss as to what it is. Any hints as to what I could possibly be doing wrong, or examples of programmatically generated layouts that run smoothly both loading and leaving fragments / activities, that would be much appreciated.
Thanks as always!