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

  • Home
  • SEARCH
  • 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 8306925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:25:40+00:00 2026-06-08T18:25:40+00:00

I need to pre load a complex layout so I can show the activity

  • 0

I need to pre load a complex layout so I can show the activity more quickly the first time:

LayoutInflater inflater = (LayoutInflater) mainActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

SlowActivity.cachedView = inflater.inflate(R.layout.activity_layout, null, false);

when SlowActivity starts…

public static View cachedView = null; 

@Override
public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);
        setContentView(this.cachedView);
      }
}

I can’t find where I read it but some one says that I’m doing a memory leak using a stati variable to store inflated layout.

Why?

Maybe I need to release some resource when activity is destroyed (never, it’s always put on the background…)

  • 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-08T18:25:41+00:00Added an answer on June 8, 2026 at 6:25 pm

    that’s because the layout , just like all views , has a reference to the activity that holds it.

    so, after the activity was closed and should be releaseed , the static variable holds a reference to a view that references to the this activity, so the app takes more memory than it should .

    views are not the only variables that you should try to avoid caching using static variables . an example for this is drawables , as seen here .

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

Sidebar

Related Questions

I need to load (de-serialize) a pre-computed list of integers from a file in
I need to pre-load some values from a php script, I'm using a $.post
I need some help understanding this bit of code pre { white-space: pre; white-space:
I have a couple of pre-existing applications which I need to run in one
I have a strong use case for pre-allocating all the memory I need upfront
For example, I need to do some pre-processing of source files before compiling. How
Possible Duplicate: Simulate steady CPU load and spikes I need to write an application
I have a JSF page where I am need to pre-check one of the
I need to read all modules (pre-compiled) from a zipfile (built by py2exe compressed)
I have so many images in a slide show and I need serve this

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.