Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4561962
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:08:55+00:00 2026-05-21T18:08:55+00:00

Please help me clear this doubt I have in my head once and for

  • 0

Please help me clear this doubt I have in my head once and for all, considering the following two cases.

Case 1:

public class Activity {
  WebView mWebview;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    initWebView();
  }

  public void initWebView() {
    mWebView = (WebView) findViewById(R.id.webview);
  }

}
  1. Does findViewById() instantiate a
    new WebView object the second time
    it is called?
  2. If the answer is ‘yes’, is the old
    WebView object (that was previously
    assigned to mWebView) automatically
    destroyed? (i.e. gets lost by being
    placed in a queue for garbage
    collection)

Case 2:

public class Activity {
  WebView mWebview;
  MyPictureListener mPictureListener;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    initWebView();
  }

  public void initWebView() {
    mWebView = (WebView) findViewById(R.id.webview);
    mPictureListener = new MyPictureListener(mWebView);
    mWebView.setPictureListener(mPictureListener);
  }

}
  1. When initWebView() is called a
    second time, is the old
    MyPictureListener object (that was
    previously assigned to
    mPictureListener) automatically
    destroyed? (i.e. gets lost by being
    placed in a queue for garbage
    collection)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T18:08:56+00:00Added an answer on May 21, 2026 at 6:08 pm

    Case 1: No matter how many times you call findViewById(R.id.webview), the object returned is the same WebView that was created when the layout was inflated by the UI framework. When you assign it to your variable, you’re just saying “I want a handle to that Object,” and that’s all it is. If you set mWebView to null, the Object still exists with references to it from the Activity’s UI, you just can’t access it from mWebView anymore.

    Case 2: Yes (insofar as ‘automatically destroyed’ works in Java). Your mWebView has a handle (a pointer) to a MyPictureListener Object, when you assign it to a new instance of that class, the reference to the old Object is lost, and the old Object is now a candidate for garbage collection.

    This is really a [grossly generalized] mini-explanation of how pointers work, which is a concept I’ve heard some people say that Java doesn’t use. That’s completely erroneous, and getting comfortable with pointers as they are used in C++ will give you much better insight into these kinds of questions in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me clear this concept. Say we have A socket port server implemented
Please help me to clear my doubt. I develop an application that performs uninstall
could you please help me with this code? <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
Please help me making this clear about instance methods in Objective C: Can send
Please help me clear the concepts with following problems: (executed and tested on linux,gcc)
Can anybody please help me to resolve this simple issue..How to clear the selection
Could someone please help. I have these two: I would like the text to
Please help I am getting the following error when I am binding the drop
Please help me out with an algorithm for the following problem - Given a
Please help me understand 2 things I found in this C code: First, there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.