I would like to express my feelings abit: Each time I go deep into the
development of android views and UIs, I spent alot of time struggling with
the subj.
I do development mostly on simulator (thats simpler and faster than having
a device). Also this helps to track the resource usage, because with 2000
ref limit I can see if anything wrong with my code.
Here are the cases I've been fighting the last time:
/* Put C# list as an array adapter into the Spinner */
var jl = this.Items.ToList();
var aadapter = new
Android.Widget.ArrayAdapter(Adapter.Activity,
Android.Resource.Layout.SimpleSpinnerItem, jl );
aadapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
v.Adapter = aadapter;
aadapter.Dispose();
This code is basically done in onStart, because of this it is invoked each
time I change orientation.
With original list of ~100 items, I'm getting overflow with just a couple
of device (or emulator) "flips":
W/dalvikvm( 6561): 714 of Ljava/lang/String; 28B (714 unique)
W/dalvikvm( 6561): 49 of Ljava/util/ArrayList; 28B (49 unique)
Having a "settings" dialog with couple of Spinners (with > 200 items in
there) it'll overflow even on real device after a minute of "Flipping".
Notice, that aadapter.Dispose() doesn't help (although it should).
Is this a bug? Doing a workaround with:
var jl = new Android.Runtime.JavaList();
foreach(var i in this.Items)
{
var js = new Java.Lang.String(i.ToString());
jl.Add(js);
js.Dispose();
};
var aadapter = new
Android.Widget.ArrayAdapter(Adapter.Activity,
Android.Resource.Layout.SimpleSpinnerItem, jl );
Everything runs fine then!
Mean its good to have a workaround, but I've lost a couple of hours to find
it (instead of doing what I should do - create the UI).
Another, more annoying issue (no workaround found so far):
In my views I have event listeners attached with
Click += ..
FocusChange += ..
TextChange += ..
etc.
Here is what I'm getting after couple of "flips":
W/dalvikvm( 4626): 468 of Lmono/android/text/TextWatcherImplementor; 12B
(468 unique)
W/dalvikvm( 4626): 16 of Lmono/android/text/TextWatcherImplementor; 20B
(16 unique)
W/dalvikvm( 4626): 1 of Lmono/android/app/Application; 12B
W/dalvikvm( 4626): 468 of
Lmono/android/view/View/OnFocusChangeListenerImplementor; 12B (468 unique)
W/dalvikvm( 4626): 17 of
Lmono/android/view/View/OnFocusChangeListenerImplementor; 20B (17 unique)
W/dalvikvm( 4626): 1 of Lxxxxroid/SettingsActivity; 204B
W/dalvikvm( 4626): 1 of Landroid/view/Window$LocalWindowManager; 20B
W/dalvikvm( 4626): 1 of
Lmono/android/view/View/OnKeyListenerImplementor; 12B
W/dalvikvm( 4626): 472 of
Lmono/android/view/View/OnClickListenerImplementor; 12B (472 unique)
W/dalvikvm( 4626): 12 of
Lmono/android/view/View/OnClickListenerImplementor; 20B (12 unique)
W/dalvikvm( 4626): 1 of Lfleux/controls/DoubleBufferedControl_HostView;
228B
W/dalvikvm( 4626): 1 of
Lmono/android/view/View/OnTouchListenerImplementor; 12B
All the views are disposed in onStop() for sure.
Tried to remove listener delegates ( doing -=) but that doesn't help.
Doing also GC.Collect(0) in each onStart() - doesn't help.
Think this is an obvious bug!
I've already heard a comment "use real device and see no issues with 50000
gref limit".
But IMHO that is something like saying "get a 4Gb device and don't care of
these memory leaks".
Igor
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid