And for those not on #monodroid... On Mar 15, 2012, at 7:07 AM, Michel wrote: ... > -- Class ListViewCategories -- > public class ListViewCategories : BaseAdapter ... > public override View GetView (int position, View convertView, > ViewGroup parent)
The intent of the `convertView` parameter is to reuse an existing instance that you allocated, thus reducing the number of objects that exist, reducing memory pressure, and keeping performance up: http://androidapi.xamarin.com/?link=M:Android.Widget.IAdapter.GetView convertView: The old view to reuse, if possible. The problem? While `convertView` is checked: > View vi = convertView; > if (convertView == null) > { > //Log.Debug("--> ConvertView null"); > vi = inflater.Inflate(Resource.Layout.DialogCategories, null); > // Log.Debug("<-- ConvertView null"); > } ...nothing is done with it. Instead, a new view is always created and returned: > LinearLayout view = new LinearLayout(context); ... > return view; > } The result, as you see, is a constantly increasing gref count. There are two solutions here: 1. Call GC.Collect() more often so that the unused LinearLayout instances will be collected. However, this may or may not work; it depends on what Android does with the returned instances. If it retains a reference to all of them, then they will never be collected. 2. Use the `convertView` parameter as it is intended: actually reuse the view. For example, in this instance the `convertView` will likely be a LinearLayout instance, as constructed by the GetView() method, so you could grab the already existing TextView instances and change their strings instead of creating a new LinearLayout + TextView object graph. - Jon _______________________________________________ Monodroid mailing list Monodroid@lists.ximian.com UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid