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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:12:27+00:00 2026-05-10T14:12:27+00:00

I have an application that reads a CSV file with piles of data rows.

  • 0

I have an application that reads a CSV file with piles of data rows. I give the user a summary of the number of rows based on types of data, but I want to make sure that I don’t read in too many rows of data and cause OutOfMemoryErrors. Each row translates into an object. Is there a way to find out the size of that object programmatically? Is there a reference that defines how large primitive types and object references are for a VM?

Right now, I have code that says read up to 32,000 rows, but I’d also like to have code that says read as many rows as possible until I’ve used 32MB of memory.

  • 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. 2026-05-10T14:12:28+00:00Added an answer on May 10, 2026 at 2:12 pm

    You can use the java.lang.instrument package.

    Compile and put this class in a JAR:

    import java.lang.instrument.Instrumentation;  public class ObjectSizeFetcher {     private static Instrumentation instrumentation;      public static void premain(String args, Instrumentation inst) {         instrumentation = inst;     }      public static long getObjectSize(Object o) {         return instrumentation.getObjectSize(o);     } } 

    Add the following to your MANIFEST.MF:

    Premain-Class: ObjectSizeFetcher 

    Use the getObjectSize() method:

    public class C {     private int x;     private int y;      public static void main(String [] args) {         System.out.println(ObjectSizeFetcher.getObjectSize(new C()));     } } 

    Invoke with:

    java -javaagent:ObjectSizeFetcherAgent.jar C 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic C# console application that reads a text file (CSV format)
I have an application that reads an input file with various user settings in
I have an application that reads lines from a file and runs its magic
I have a windows mobile 5.0 application (smartphone) that contains a flat data file
I have an application that reads a .properties file at start up containing key/values
I have a SL application that reads some data from the database, which I
We have an application that reads Word documents and imports them into our file
I have an application that reads a database and outputs alerts to any dependencies
I have an application that reads a table from a database. I issue an
I had an application that was downloading a .CSV file from a password-protected website

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.