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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:42:36+00:00 2026-05-28T14:42:36+00:00

C#, Mono for Android. I need to output a large portion of combined data

  • 0

C#, Mono for Android. I need to output a large portion of combined data into ListView. To achieve this, I use the following obvious approach with Adapter:

class ItemInfo
{
    public string Id;
    public string Name;
    public string Description;
    public int Distance;

    //Some more data
}


class ItemAdapter : ArrayAdapter<ItemInfo>
{
    public WorldItemAdapter (Context context, int textViewResourceId, List<WorldItemInfo> items) :
    base(context, textViewResourceId, items)
    {   
    }

    //...

    public override View GetView (int position, View convertView, ViewGroup parent)
    {
        //Some stuff to format ListViewItem
    }
}


public class OutputActivity : Activity
{
    ListView _listView;

    //...

    void FillList (object SomeParameters)
    {
        var adaptedList = someDataSource.Where().Join().Union().//anything can be imagined
        .Select ((item, item2, item3) => 
            new ItemInfo (){                
                Id = item.Id,
                Name = item.Name,
                Description = String.Format(..., item2, item3),                 
                Distance = ...,
                //so on             
            }
            ).OrderBy ((arg) => arg.Name).ToList ();

        _listView.Adapter = new ItemAdapter (this, Resource.Layout.ListItemFormat, adaptedList  ());

    }
}

This works very fine… until I start to refresh my ListView frequently. If I generate many ItemInfo’s (by refreshing my view, for example), I reach GREF limit soon (described here, “Unexpected NullReferenceExceptions” section), and my application crashes. Looking into Android log, I can see thousands of Android.Runtime.IJavaObject objects, which overflow GREF limit.

According to concepts of Mono VM + Dalvik VM bridge I can understand, that my ItemInfo’s need to be passed to Dalvik VM, wrapped to IJavaObject and to be formatted in ListView by native environment – this creates GREF’s. As long as garbage collecting is a non-determined process, if I call FillList() many times, old, already used ItemInfo’s stay into memory, leaking.

How can I avoid leaking? Or, possible, is there another way to output large portions of formatted data into ListView? I tried:

  • I can’t reduce the number of ItemInfo’s, as long as I need to place my data somehow.
  • I can’t follow this advice, as long as my ItemInfo is not an IJavaObject.
  • As a temporarily solution, I call GC.Collect() every time I need to refresh list, but this looks not a clean way. Also, if I need to output more than 2к objects into list, this doesn’t help.
  • 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-28T14:42:37+00:00Added an answer on May 28, 2026 at 2:42 pm

    Answer found. I’ve inherited my ItemInfo class from Java.Lang.Object explicitly and now can call Dispose() when object is no longer needed. This kills leaking GREFs.

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

Sidebar

Related Questions

I have the following problem. We have build an app with mono for android.
I have a mono android project. I can use monodevelop to build the apk
what's the best database we can use to develop application for mono android? best
I'm using Mono for Android and I'd like to use a scheduled timer to
I've installed Mono For Android Trial on my computer And I want to use
There is a possibility to use C# library with Mono for Android from Java
I'm absolute beginner when it comes to mono for android . I've used following
i'm trying to use gmap on android (trying to develop it using mono for
mono creates its own debug targets called .mdb files when you use the mcs
Mono won't fire the following code: I get internal server error 500, error writing

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.