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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:44:04+00:00 2026-06-13T14:44:04+00:00

I have a very strange memory problem with my Android app. My app use

  • 0

I have a very strange memory problem with my Android app.
My app use 3 classes that are the following:

public class RGB 
{
    public int R;
    public int G;
    public int B;
}

public class CMYK 
{
    public int C;
    public int M;
    public int Y;
    public int K;
}

public class COLOR 
{
    public String id;
    public CMYK cmyk = new CMYK();
    public RGB rgb = new RGB();

    public COLOR(String id, int c, int m, int y, int k, int r, int g, int b)
    {
        this.id = id;

        this.cmyk.C = c;
        this.cmyk.M = m;
        this.cmyk.Y = y;
        this.cmyk.K = k;

        this.rgb.R = r;
        this.rgb.G = g;
        this.rgb.B = b;
    }
}

then somewere in the code I have to load 2000 colors from a file (file is about 65K lenght and has exactly 2000 records) and is placed in assets folder

public COLOR[] color_list = new COLOR[2000];
...
...
do
{
    s = reader.readLine();
    if (s != null)
    {
        String[] x = s.split(" ");
        COLOR c = new COLOR(x[0], Integer.parseInt(x[1]), Integer.parseInt(x[2]), Integer.parseInt(x[3]), Integer.parseInt(x[4]), Integer.parseInt(x[5]), Integer.parseInt(x[6]), Integer.parseInt(x[7]));
        color_list[j++] = c;
    }

} while (s != null);

after this the app will crash and stop working. If I remove the do..while all is working, so I think my array will be more and more and more then 65K, what I have done wrong? On Android LogCat I have reached the full of HEAP space (26MB) !!!

Best regards
GMG

  • 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-13T14:44:05+00:00Added an answer on June 13, 2026 at 2:44 pm

    I don’t think that code is responsible of the OutOfMemoryException. Maybe there are other fields you don’t mention, but without running the code one can’t tell.

    However there may be a small leak when you create the ID. Whenever you create a String from an existing one (either substring()-based or methods in the regex package), the returned string keeps an internal reference to the old one: it’s just a thin wrapper around the old sequence of characters, just with different start and different length. This means that you’d better create your ID like this

    String id = new String(x[0]);
    

    This way you don’t keep the whole line in memory just to store a few characters.

    However, this is an optimization, since you state that your file is 65KB, so even if you retain it all in-memory, it wouldn’t crash your application. Post the whole code so we can run and analyze it.

    BTW, you can save an indentation level this way:

    String line;
    Pattern pattern = Pattern.compile(" "); // Help the GC ;)
    
    while ((line = in.readLine()) != null) {
        String[] data = pattern.split(line);
    
        // Ugly, but still better than a 8-args constructor
        RGB rgb = new RGB(data, 1, 3);
        CMYK cmyk = new CMYK(data, 4, 4);
    
        // the best would be a constructor like Color(String[8])
        colors[j++] = new Color(new String(data[0]), rgb, cmyk);
    }
    

    I also changed the API a bit (I found this more comfortable)

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

Sidebar

Related Questions

I have a very strange memory leak problem, it seems that sqlite3_step is doing
I have a very strange problem. I have a working WCF service. [ServiceContract] public
I have a very strange error happening in an App that has been working
I have very strange problem while I am submitting a practice problem on codechef.
I have very strange behaviour of Java Date class: System.out.println(new Date().toGMTString()); long l =
I have a very strange, very repeatable leak that doesn't appear to have anything
I have a very strange problem when I'm testing my application on device. I
Hello I have very strange problem and maybe some of you could help my.
Have a very strange problem with Apache .htaccess URL Rewriting and Redirection. Here's my
I have a very simple SDL program that uses only 1MB of memory with

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.