[mono-android] Excessive JNI global references (2001) on hardware
Jonathan Pryor
jonp at xamarin.com
Fri Feb 3 15:00:22 UTC 2012
On Feb 3, 2012, at 7:54 AM, PVoLan wrote:
> Please, look at this test case https://github.com/PVoLan/TestAccelerometer
Your sample is is largely a simplified version of:
http://bugzilla.xamarin.com/show_bug.cgi?id=1084
The current "fix" (workaround) is to dispose of `val` within SensorListener.OnSensorChanged():
public void OnSensorChanged (SensorEvent e)
{
var val = e.Values;
try {
Android.Util.Log.Info("-------------","Works for: " + (DateTime.Now - created));
Android.Util.Log.Info("-------------",string.Format("X: {0} Y: {1} Z: {2}", val[0], val[1], val[2] ));
} finally {
((IDisposable) val).Dispose ();
}
}
A future release will improve matters by automatically calling GC.Collect() when we pass a certain gref threshold, but even that fix may not be ideal as it may result in too many collections (e.g. if you have an animation loop, you want to control when the GC runs), so explicitly disposing of wrappers may still be required even after the implicit GC.Collect() call is in place.
- Jon
More information about the Monodroid
mailing list