Users Pricing

forum

Home Forums In Java, what is the best way to determine the size of an object? – MindStick

In Java, what is the best way to determine the size of an object?

Anonymous User 2301 11 Aug 2015
For example, let's say I have an application that can read in 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 an easy 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. Maybe that is a different question, but I'd still like to know.

1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md