Hi,

As fast and temporary solution I made a derived class from WeakReference
with extended get_Target behaviour. It uses JNI to check the reference. It
is not a "silver bullet", because this is only a workaround, as an
example, it may be possible that Dalvik already allocated another
object with the same address, so be ready for some kind of InvalidCast
exception in this case. So i desided to follow next two rules:
1. avoid use of WeakReferences with peer objects.
2. write cache for java objects using java.

My temporary solution below:

namespace Android.Workarounds
{
 using Android.Runtime;
 public class WeakReferenceWorkaround : System.WeakReference
 {
  public WeakReferenceWorkaround(object target) : base(target)
  {
  }
  public WeakReferenceWorkaround(object target, bool trackResurrection) :
base(target, trackResurrection)
  {
  }
  public override object Target
  {
   get
   {
    var target = base.Target;
    if (target != null)
    {
     var javaObject = target as IJavaObject;
     if (javaObject != null)
     {
      var javaLocalRef = JNIEnv.ToLocalJniHandle(javaObject);
      if (javaLocalRef == null || javaLocalRef == IntPtr.Zero)
       return null;
      JNIEnv.DeleteLocalRef(javaLocalRef);
     }
    }
    return target;
   }
  }
 }
}

I just added next lines before cache implementation.
#if __ANDROID__
 using WeakReference = Android.Workarounds.WeakReferenceWorkaround;
#endif

Regards
2012/8/29 bjarke [via Mono for Android] <
[email protected]>

> Hi,
>
> Thank you for the response. Lets hope they get it fixed fairly quickly. Do
> you use any alternative way of caching images while waiting?
>
> Regards
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://mono-for-android.1047100.n5.nabble.com/Image-caching-tp5710451p5711618.html
>  To unsubscribe from Image caching, click 
> here<http://mono-for-android.1047100.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5710451&code=YWxleGV5c2JAZ21haWwuY29tfDU3MTA0NTF8MjEwOTg4MzMwNg==>
> .
> NAML<http://mono-for-android.1047100.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: 
http://mono-for-android.1047100.n5.nabble.com/Image-caching-tp5710451p5711651.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to