• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

readObject() eat memory !!!

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello i have problem when i read object from file that generated from this code :


this is how i read the object, i'm using thread because i want to keep up to date with the file, so it will keep reading in interval... the file that i read is about 15mb... but i dunt know how when i read object it will consume about 100-150mb memory in heap. i'm using jprofiler to measure.

this is code how i read this file :


This is main program :


does anyone know, why my program consumes about 100-150mb when deserialize object from 15mb file.

thank you
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you've got about 45 MB worth of objects there (1 million times about 20 bytes for an Integer and about 24 for a Map.Entry), plus there's the Hashtable that the ObjectXStreams will use to keep track of whether or not they're already serialized an object, which will consume another ~24M or so; so it looks like either the read or write program will not quite fit into the default 64M heap. I'd think that either one would run within a 100M or so, and not need any more than that.That's the Java heap itself, mind you; the JVM's native code and such consume additional space outside of the heap.
 
Wiyanto Ngasinur
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for the reply before. but how do you know Integer object cost 20byte and MapEntry 24byte. do you have any reference site, so i can learn how the calculation size.



thank you
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no official documentation for that, and it of course varies across JVMs. But the rule I always use, and it works well for me, is to allow 16 bytes for an object, plus the size of its member variables. An Integer has one "int" member, so it's 20 bytes. A Map.Entry has at least two reference variable entries to point to the key and value, so I said 24 bytes. But now that I think of it, it probably has at least one more member so that entries can be in a linked list...

OK, I went and looked at the JDK source code. A Hashtable.Entry has four members: an int to hold a hash value, and three reference variables, so I would count that as 16 + 4 + 12 = 32 bytes; my earlier estimate was a little low, then.
 
Wiyanto Ngasinur
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow, that's really explain much ! thank you
 
Legend has it that if you rub the right tiny ad, a genie comes out.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic