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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:35:47+00:00 2026-06-14T19:35:47+00:00

This question is an extension to this question , that I posted yesterday. I

  • 0

This question is an extension to this question , that I posted yesterday. I found a possible Memory Leak, and dealt with this the proper way. One of the memory leaks where caused by a non static inner class, more precise a non-static Handler.

But I am facing a new memory leak issue today. I’ve read this post, the essence is based around the Context, Activity or Application Context.
enter image description here

This is the Pie chart that I got from the Eclipse Memory Analyzer

I have seen that there is changes in the Remainder of this Pie chart, after fixing issues with the Handler, the Remainder has increased with 10.6 MB.

But over to the Context Issue, the Problem Suspect 2 gives me a hint where to look

35 instances of "android.widget.FrameLayout", loaded by "<system class loader>" occupy 39 218 464 (39,94%) bytes. 

Biggest instances:

•android.widget.FrameLayout @ 0x425aa258 - 3 266 728 (3,33%) bytes. 
•android.widget.FrameLayout @ 0x425d9b20 - 3 266 728 (3,33%) bytes. 
•android.widget.FrameLayout @ 0x42609258 - 3 266 728 (3,33%) bytes. 
•android.widget.FrameLayout @ 0x4260a248 - 3 266 728 (3,33%) bytes. 
•android.widget.FrameLayout @ 0x42925960 - 3 266 728 (3,33%) bytes. 
•android.widget.FrameLayout @ 0x429808e0 - 3 266 728 (3,33%) bytes. 
•android.widget.FrameLayout @ 0x429a4350 - 3 266 728 (3,33%) bytes. 
•android.widget.FrameLayout @ 0x429d9b20 - 3 266 728 (3,33%) bytes. 
•android.widget.FrameLayout @ 0x429e5710 - 3 266 728 (3,33%) bytes. 
•android.widget.FrameLayout @ 0x42a28c98 - 3 266 728 (3,33%) bytes. 
•android.widget.FrameLayout @ 0x42a51b80 - 3 266 728 (3,33%) bytes. 
•android.widget.FrameLayout @ 0x46a8caf0 - 3 266 728 (3,33%) bytes. 

It tells me that the memory leak occurs where I’m using a FrameLayout. The only place where I use a FrameLayout, is in my Splash Screen.

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    utils = new AppUtils(getApplicationContext());
    pd = (ProgressBar) findViewById(R.id.pd);
    progress = (TextView) findViewById(R.id.progress);
    version = (TextView)findViewById(R.id.version);
    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    SharedPreferences.Editor prefEditor = prefs.edit();
    prefEditor.putString("firstpw", "first");
    prefEditor.commit();

    folder = new CreateApplicationFolder(getApplicationContext(), true); 
    boolean isSDPresent = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);

    if (!isSDPresent) {
        ErrorDialog dialog = new ErrorDialog(getApplicationContext(), getResources().getString(R.string.sdCardTitle),
                getResources().getString(R.string.sdCardContent),
                getResources().getString(R.string.ok), 2);
        Log.i("SDCARD: ", "Is Not Present");
        dialog.canCancelDialog(false);

    } else {
        Log.i("SDCARD: ", "Is Present");

        version.setText("Version: " + utils.getAppVersion()); 

        try {
            new ReadConfig(Splash.this, pd, progress).execute("");
        } catch (ParserConfigurationException e) {
            Log.e("Parser: ", e.getMessage());
        } catch (SAXException e) {
            Log.e("Sax: ", e.getMessage());
        } catch (IOException e) {
            Log.e("IO: ", e.getMessage());
        }
    }
}

I suspect that the memory leak occurs when I’m sending the Activity context to the AsyncTask ReadConfig, like this:

try {
            new ReadConfig(Splash.this, pd, progress).execute("");
        } catch (ParserConfigurationException e) {
            Log.e("Parser: ", e.getMessage());
        } catch (SAXException e) {
            Log.e("Sax: ", e.getMessage());
        } catch (IOException e) {
            Log.e("IO: ", e.getMessage());
        }

And in the ReadConfig class, I’m also using this context to start a new Activity in the onPostExecute method, which will keep this context alive.

protected void onPostExecute(String result) {

        if (result.equals("noConfig")) {
            Toast.makeText(context, context.getResources().getString(R.string.configNotFound),
                    Toast.LENGTH_LONG).show();
            Intent mainIntent = new Intent(context, MainClass.class);
            context.startActivity(mainIntent);
        }
        else if(result.equals("pathnotFound")) {

            new ErrorDialog(context, context.getResources().getString(R.string.noBTFolderTitle), context.getResources().getString(R.string.noBtFolderContent), context.getResources().getString(R.string.exit), 2);

        } else {
            Intent mainIntent = new Intent(context, MainClass.class);
            context.startActivity(mainIntent);
        }
    }

I need the context to start this new Activity, getting strings from the resources and so on. Is there any possible way I can do this differently to avoid the memory leak? Thanks for reading this big post, and just add a comment if you need more code or anything else.

Thanks in advance.

  • 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-06-14T19:35:48+00:00Added an answer on June 14, 2026 at 7:35 pm

    You, probably, should try to use Application Context and not the Activity context wherever possible (it’s not always possible).

    To access your Application context from everywhere you can define your own application class

    class MyApp extends Application
    {
    private static MyApp mInstance;
    
    @Override
    public void onCreate()
    {
       mInstance = this;
    }
    
    public static Context context()
    {
       return mInstance.getApplicationContext();
    }
    
    }
    

    Then you declare this class in your manifest

    <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:name="com.myapp.MyAppClass">
    

    and use MyApp.context() wherever applicable

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

Sidebar

Related Questions

My question is an extension of that one: Immutable numpy array? This code prints
I have a question that's somewhat of an extension of this thread . I
This question is an extension to the one raised here: Using factory_girl in Rails
this question is a extension of one made in Best Solution Architecture , basically
This question is an extension of this question . It is good that I
This is a hypothetical question: I want to build a Chrome extension that'll track
this question is an extension of my previous question that you can find here:
I've seen this question posted here previously but I'm not satisfied that I understand
This is an exension to this question where we learn that we can set
this question is an extension of the question here i tried to extend Dane's

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.