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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:44:18+00:00 2026-06-15T20:44:18+00:00

I’m getting Out of memory errors. I checked the DDMS and find that the

  • 0

I’m getting Out of memory errors. I checked the DDMS and find that the places I allocate more memory is in the getView() method in my adapters. Is it a better way for me to create objects then this way:

view=new ImageView(myContext);

This is one example of my getView() method:

public View getView(int position, View convertView, ViewGroup parent) {
    View view = null;
    if (convertView==null){
        view=new ImageView(myContext);
        view.setLayoutParams( new AbsListView.LayoutParams(columnWidth,columnWidth));
        view.setBackgroundColor(Color.GRAY);
    }else{
        view=convertView;
        convertView.setBackgroundColor(Color.GRAY);
    }
    return view;
}

I get the context in the c’tor:

public emptySquaresAdapter( Context myContext,) {
    super();
    this.myContext=myContext;
}

I read about context leak, is that the case?

EDIT:

In this case I show all the views in the screen at once, so the converted view is never used (I don’t need to scroll to show more views).

this adapter shows 12 squares on the screen. The method getView is called 12 times with the position 0 (I guess to measure all the child vies) and only then continues to position 1,2,3…
Why doe’s it happens? Can this make the OOM problem?
I call this adapter from another adapter, and I guess that what makes everything complicated.

I also unbind all drawables at onDestroy, and set imageView.getDrawable().setCallback(null) to all of the imageViewsIt still doesn’t work

  • 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-15T20:44:20+00:00Added an answer on June 15, 2026 at 8:44 pm

    The code you posted is ok. The problem is, probably, somewhere else.

    P.S. Why do you store context object? You can get it any time you need in your getView() method by calling parent.getContext()

    And to my experience, it doesn’t matter what kind of context you pass as long as you don’t hold onto that (what you are actually doing).

    But if your adapter itself is not stored somewhere and is just a part of an activity it should be ok, since adapter will just get gc’ed with activity.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.