title: dark relation between execution thread and weakreferences?
body: <p>I'm facing a strange problem I don't know even how to properly explain, but I hope somebody has faced this pseudo-problem and can tell me more or less why it happens.</p>
  
  <p>I have a complex activity that occassionally spans threads to load resources.</p>
  
  <p>It looks like that, somehow, if I assign a weakreference in the execution context of one thread, later on, on the UI thread, it returns null.</p>
  
  <p>I'm absolutely sure I don't null that reference, as I only assign it on one place, that is like:</p>
  
  <pre><code>function assignReference(FunqSlide slide) {
  
      mWeakEditSlide=new WeakReference&lt;FunqSlide&gt;(newSlide);
      if (Conf.LOG_ON) Log.d(TAG, "SetSlide_internal "+index+"="+mWeakEditSlide+"-&gt;"+mWeakEditSlide.get());
      .
      .
  }
  </code></pre>
  
  <p>And this produces the trace with the expected weakreference assigned to a valid object</p>
  
  <pre><code>    06-01 17:40:50.030: D/FunqStory[Hiphop en LA](18390): SetSlide_internal 4=java.lang.ref.WeakReference@41625d18-&gt;FunqSlide{40f60728}
      .
      . next is processing 
  </code></pre>
  
  <p>But the program flow continues and, slightly later on, a function accesses the previously created reference, but it is null!!! </p>
  
  <pre><code>    06-01 17:40:53.330: D/FunqStory[Hiphop en LA](18390): *** CURRENT EDIT SLIDE ID weakreference is null!!!
  
      06-01 17:40:53.330: E/AndroidRuntime(18390): FATAL EXCEPTION: main
      06-01 17:40:53.330: E/AndroidRuntime(18390): java.lang.NullPointerException
      06-01 17:40:53.330: E/AndroidRuntime(18390):    at com.regaliz.funq.gui.Props_LayerList.loadSlide(Props_LayerList.java:77)
      06-01 17:40:53.330: E/AndroidRuntime(18390):    at com.regaliz.gui.fragments.FunqHelperSupport$Frag.setup_native_pane(FunqHelperSupport.java:1028)
      06-01 17:40:53.330: E/AndroidRuntime(18390):    at com.regaliz.libneo.NativeStory$ActionBarHandler.handleItemSelected(NativeStory.java:1612)
  </code></pre>
  
  <p>And, if had nulled it, there should be a debug trace of the function assignRefennce before the nullpointerexception, but there isn't, what indicates that something outside my code is nulling the reference for me.</p>
  
  <p>Of course I've solved it just doing the stuff in the same thread, but I'd really want to know what's going on!</p>
  
  <p>Any pointers? or WeakReferences? xD</p>
  
  <p>Thanks in advance !</p>