title: Android Fragment Webview Memory Leak
body: <p>I could use some help identifying an issue in my code regarding fragments and webviews. I tried implementing some of the solutions in the other threads unsuccessfully. I've tested this same fragment being replaced without the webview being created inside and there is no leak. Any ideas? If not, can anyone pose an alternate solution?</p>
  
  <p>Here's my webview fragment:</p>
  
  <pre><code>public class CustomWebViewFragment extends PageFragment
  {
  
  private LinearLayout mWebContainer;
  private WebView mWebView;
  
  
  /**
   * public View onCreateView(LayoutInflater inflater, ViewGroup container,
   * Bundle savedInstanceState)
   */
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
  {
      View v = inflater.inflate(R.layout.fragment_one, container, false);
  
      //If I comment this line out, there is no memory leak
      mWebView = new WebView(this.getActivity().getApplicationContext()); 
  
      return v;
  }
  
  
  /**
   * public void onDestroy()
   */
  @Override
  public void onDestroy()
  {
      super.onDestroy();
      if (mWebView != null)
      {
          mWebView.loadUrl("about:blank");
          mWebView.destroy();
          mWebView = null;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here's how I'm changing fragments:</p>
  
  <pre><code>@Override
  public void onNavSelected(String page)
  {
      if (page != null &amp;&amp; !page.equals(""))
      {
          System.gc();
          if (page.equalsIgnoreCase(GlobalConstants.PAGE_1))
          {
              mCurrent = getFragment(); // Creates a new fragment
              getSupportFragmentManager().beginTransaction()
                  .replace(R.id.main_fragment, mCurrent).commit();
          }
      }
  }
  </code></pre>