[mono-android] GridView not releasing view objects

HSSoftware david at headstandsoftware.com
Thu Dec 15 13:52:24 EST 2011


Sorry again, formatting got mangled ...

I have an activity, whose content view includes a GridView. This GridView is
backed up by a custom adapter derived from 'Java.Lang.Object, IListAdapter'.
The data set behind the adapter include maybe 2300 objects, though only 80
views are visible at a time on the screen, thus the adapter should only be
generating 80 or so views at a time. Each view comes from a layout,
referencing a custom view, that is simply a subclass of ImageView: 

<?xml version="1.0" encoding="utf-8"?>
<aakf.screens.wallscreen.WorkThumbImageView
xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/Thumbnail_ImageView"
    android:layout_width="100dip"
    android:layout_height="100dip"
    android:scaleType="centerCrop"
    android:paddingBottom="2dip"
    android:paddingTop="2dip"
    android:paddingLeft="2dip"
    android:paddingRight="2dip"
    android:background="#A0A0A0"
    android:cropToPadding="true"
           />

Everything works fine, the images display, I can scroll and all. Rotation
works fine. No problem. But if you keep rotating, and rotating, and
rotating, there is a memory leak. 

I generated an HPROF, looked at it with Eclipse Memory Analyzer and ... 

4,296 instances of "aakf.screens.wallscreen.WorkThumbImageView", loaded by
"dalvik.system.PathClassLoader @ 0x40515960" occupy 2,884,760 (42.03%)
bytes. 

Keywords dalvik.system.PathClassLoader
0x40515960 aakf.screens.wallscreen.WorkThumbImageView 

It appears that when the activity is being destroyed upon rotation, somehow
the GridView is not releasing instances of WorkThumbImageView that had been
created! I checked, and indeed the activities are being OnDestroy'ed as I
rotate. 

Something wrong in my layout? Something special I need to do in the
WorkThumbImageView class? I have attached the class.

--
View this message in context: http://mono-for-android.1047100.n5.nabble.com/GridView-not-releasing-view-objects-tp5078401p5078410.html
Sent from the Mono for Android mailing list archive at Nabble.com.


More information about the Monodroid mailing list