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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:26:13+00:00 2026-05-28T00:26:13+00:00

I read the link at http://developer.android.com/resources/articles/avoiding-memory-leaks.html and need to know what should be done

  • 0

I read the link at http://developer.android.com/resources/articles/avoiding-memory-leaks.html
and need to know what should be done if I create a button

Button button = new Button(this) in an activity

and assign the button to a static variable “sButton”

sButton = button

What should be done in the onDestroy() method of the activity to avoid memory leakage.Will assigning sButton=null do the job sufficiently?Or do we have to call some other methods on sButton.

Suppose we do the same thing as above but instead of button we save the activity class itself or activity context to a static variable,what should be done so that to delete all reference of the activity so that the activity could be destroyed properly incase of memory shortage.

  • 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-28T00:26:13+00:00Added an answer on May 28, 2026 at 12:26 am

    The example states that doing this with a simple drawable will leak the entire activity because of a chain of references. If you, instead of saving the drawable, save the activity you fall into the same problem.

    Setting the reference to null should solve the problem, look for the exampled cited in the article. But beware of keeping an unneeded activity in memory.

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

Sidebar

Related Questions

I read this here : http://developer.db4o.com/Forums/tabid/98/aft/5027/Default.aspx#20510 The link is from 2008 I am hoping
I just read this link http://msdn.microsoft.com/en-us/library/ms186243.aspx Here is the code to create table and
I have one link http://devappandroid.com/Android_App/test_uploada%20.html on that i am uploading A Image and as
Firstly, I have read these: (1) http://www.gaiagps.com/news/article/iOS5%20Breaks%20Data%20Storage%20and%20Crushes%20My%20Soul (2) http://iphoneincubator.com/blog/data-management/local-file-storage-in-ios-5 (I can not submit more
Facebook gives a JSON stream like this: actions: [ { name: Comment, link: http://www.facebook.com/100000335233539/posts/193845507303289
How do I return the comment property from exif_read_data link: http://www.php.net/manual/en/function.exif-read-data.php
Having read this link on RBAR and this , my understanding of RBAR amounts
following this link i was able to load and read pixels from a .gif.
I haven't read much about it, but the author at the link below recommends
For what I've read I need Python-Dev, how do I install it on OSX?

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.