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 3934620
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:44:11+00:00 2026-05-19T23:44:11+00:00

I have extended View and passed it an instance of my Activity so the

  • 0

I have extended View and passed it an instance of my Activity so the view can access some member variables and methods.

But now I’m thinking this could be a potential memory leak, because even after the Activity is destroyed, it still has a reference to the view in a member variable, and vice versa. So the garbage collector may never clean them up.

However, I’ve seen in some of the Google API demos and examples cases where they have passed the Activity to the View as a listener.

  • 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-19T23:44:12+00:00Added an answer on May 19, 2026 at 11:44 pm

    This is fine, remember that any ordinary View you create programatically with its constructor takes a Context as its argument- usually the Context you give the constructor is just this, or the Activity itself. So your View already has a reference to its Activity. You can also get this inside the View class using its getContext() method.

    When the Activity is destroyed, it will remain in memory until the GC can remove it. But as part of its onDestroy method, it sets the reference to any Views it contains to null, and so on down the View tree. Then the GC can safely remove all its component Views. Once that is complete, there are no references left to the Activity and another GC pass may delete it.

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

Sidebar

Related Questions

My question may be a bit unclear, but I have extended the View class
I have succesfully extended a view and overridden the onDraw() method I can draw
I have extended the android View class, and now I want to define a
I have extended the AbstractTableModel to suit my requirements. Now this table can be
I have some code setup in an extended view which does some drawings which
I have a Controller/View for a generic list of items, that can be extended
I am trying to draw an animation. To do so I have extended View
I have a strange problem with my Custom View Group: It is an extended
i've built a BaseAdapter extended class for my list view.. inside i have a
In my application I have an extended User model called UserProfile. This user can

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.