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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:42:17+00:00 2026-06-11T16:42:17+00:00

I’m developing an application which loads lots of data (like from csv). I’m creating

  • 0

I’m developing an application which loads lots of data (like from csv).

I’m creating List<List<SimpleCell>> and loading into it the readed cells.
SimpleCell class contains 5 * String, every String have on average 10 characters.

So I’m thinking that if I read 1000 rows – each containing 160 columns – that gives 1000*160=160 000 SimpleCell‘s instances – it’ll be something about 160 000 * sizeof(SimpleCell.class) =~ 160 000 * 10 * 5 = 8 000 000 bytes =~ 7.63 MB.

But when I’m looking at jconsole (and after clicking Perform GC) memory usage is something about 790MB. How could this be?

Note that I don’t store any references to any “temporary” objects.
Here is the code when the memory usage rises:

        for(int i = r.getFromIndex(); i <= r.getToIndex(); ++i) {
            System.out.println("Processing: 'ZZ " + i + "'");
            List<SimpleCell> values = saxRead("ZT/ZZ " + i + "");
            rows.add(values);
        }

saxRead just creates inputStream parses it with SAX, closes stream, and returns cells (created by SAXHandler) – so there are only local variables (that I think will be garbaged in the near ‘future’).

I’m getting out of heap error when reading 1000 rows but I must read approximately 7k.

Obviously – there’s something that I don’t know about jvm memory.
So why memory usage is so huge when loading this relatively small amount of data?

  • 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-11T16:42:18+00:00Added an answer on June 11, 2026 at 4:42 pm

    A String uses 48 bytes plus the size of the text * 2. (Each character is 2 bytes) The Simple Cell object uses 40 bytes and the List of them uses 1064 bytes.

    This means each row uses 1064 + 160 * 40 + 5 * 180 * (48 + 20) bytes or about 68K. If you have 1000 lines you will be using about 70 MB which is much less than what you are seeing.

    I suggest you use a memory profile to see exactly how much memory is being used by what. e.g. VisualVM or YourKit.

    Depending on how you construct the Strings you retain even more memory than this. For example its likely you are retaining a reference to the original XML as when you take a substring of it, you are actually holding a copy of the original.


    You may find this class useful. It will reduce the amount of memory Strings use if they are using more than they need and reduce duplicates using a fixed size cache.

    static class StringCache {
        final WeakReference<String>[] strings;
        final int mask;
    
        @SuppressWarnings("unchecked")
        StringCache(int size) {
            int size2 = 128;
            while (size2 < size)
                size2 *= 2;
            strings = new WeakReference[size2];
            mask = size2 - 1;
        }
    
        public String intern(String text) {
            if (text.length() == 0) return "";
    
            int hash = text.hashCode() & mask;
            WeakReference<String> wrs = strings[hash];
            if (wrs != null) {
                String ret = wrs.get();
                if (text.equals(ret))
                    return ret;
            }
            String ret = new String(text);
            strings[hash] = new WeakReference<String>(ret);
            return ret;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

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.