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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:21:12+00:00 2026-05-28T06:21:12+00:00

I am a beginner to Android but I seem to be running across a

  • 0

I am a beginner to Android but I seem to be running across a problem where my Activities are never being garbage collected because there is a still a reference to the Activity in the non-static inner class of my thread the variable is called this$0 I found it by using the MAT in Eclipse. Below is my current setup.

public class MyActivity
-->class MySurfaceView
---->class MyThread

When trying to find information on if it was possible to remove this last instance it appears I can’t after finding a very useful article here.

Avoid non-static inner classes in an activity if you don’t control
their life cycle, use a static inner class and make a weak reference
to the activity inside. The solution to this issue is to use a static
inner class with a WeakReference to the outer class, as done in
ViewRoot and its W inner class for instance

So it seems like I shouldn’t use this system of inner classes or use WeakReferences.

My question is, why do the sample projects use the inner class system with no WeakReferences? Are they still garbarge collected? Or were they designed not to deal with garbage collection?

Is it likely my application has a code problem, meaning I should correct my code and still keep my inner classes? Or should I seperate the classes (or introduce WeakReferences)?

  • 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-28T06:21:13+00:00Added an answer on May 28, 2026 at 6:21 am

    You can use inner classes make them static and have a Weak Reference the parent.
    Also store long living objects in Application Context.

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

Sidebar

Related Questions

I am a beginner in Android platform and i have encountering a serious problem.
I'm a beginner in Android development but not in programming itself. Anyway, this question
I'm a beginner to android. I need to know is there any intent to
Well, I am beginner in Android and java, but I'm trying to learn. My
I am only a beginner to Android, but I have noticed a number of
I'm not a beginner at C# but I really need to increase my understanding,
I am beginner to Animation in Android. I want to set animation like Pendulum(Swing
Beginner here, I have a simple question. In Android what would be the best
Brand new to android and facing a weird problem.Check out the code below FirstActivity.java:
I am a beginner android developer and I am trying to have a button

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.