On Sep 4, 2012, at 12:51 PM, NebulaSleuth <[email protected]> wrote:
> The problem seems to be in my Sensor Handler, but for the life of me I don't
> know what is wrong. I have boiled it down to simply reading the X,Y,Z data.
> public void OnSensorChanged(SensorEvent sensorEvent)
> {
> // If I don't do the following three lines, GREF counts don't go
> haywire
> float X = sensorEvent.Values[0];
> float Y = sensorEvent.Values[1];
> float Z = sensorEvent.Values[2];
> // sensorEvent.Dispose(); //Dispose does not seem to help
> }
>
> Am I forgetting/missing something? It seems pretty simple.
The problem is marshaling: _each_ access to `sensorEvent.Values` generates a
_new_ JavaList<T> instance, which takes out a gref; the above code will thus
take 3 grefs per invocation, and they won't be collected until a full GC is
performed.
The workaround is to dispose of things:
// https://bugzilla.xamarin.com/show_bug.cgi?id=1084#c6
var values = sensorEvent.Values;
try {
float X = values [0];
float Y = values [1];
float Z = values [2];
// ...
} finally {
var d = values as IDisposable;
if (d != null)
d.Dispose ();
}
- Jon
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid