java.sizeOf
Introduction
With java.SizeOf you can measure the real memory size of your Java objects. Download it here
The project is a little java agent what use the package java.lang.Instrument introduced in Java 5 and is released under GPL license.
java.sizeOf is in early stage of development but it's quite usable and it was very useful for us to know the memory size of our HttpSession's objects. The best use of the library is inside an aspect to avoid dependencies in your code.
Quickstart
1. include sizeOf.jar in the classpath of your application and use it in your code like this:
import net.sourceforge.sizeof
...
SizeOf.skipStaticField(true); //java.sizeOf will not compute static fields
SizeOf.skipFinalField(true); //java.sizeOf will not compute final fields
SizeOf.skipFlyweightObject(true); //java.sizeOf will not compute well-known flyweight objects
System.out.println(SizeOf.deepSizeOf(<your object>)); //this will print the object size in bytes
You can dump object's size setting the min size to log (if you don't specify an output stream standard out is used):
SizeOf.setMinSizeToLog(1024); //min object size to log in bytes
SizeOf.setLogOutputStream(new FileOutputStream("<your log file>"));
Use the humanReadable() method to get the object size in byte, kilo or mega (if you need giga your in trouble guy!):
SizeOf.humanReadable(SizeOf.deepSizeOf(<your object>));
2. start your application with the following JVM parameter:
-javaagent:/path_to/sizeOf.jar
3. have fun!
Please use SourceForge forum for reporting any bug, comment or suggestion.
http://sizeof.sourceforge.net/
java.sizeOf的更多相关文章
- 数据库数据在Java占用内存简单估算
数据库数据在Java占用内存简单估算 结论: 1.数据库记录放在JAVA里,用对象(ORM一般的处理方式)须要4倍左右的内存空间.用HashMap这样的KV保存须要10倍空间; 2.假设你主要数据是t ...
- Spark案例分析
一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...
- Java 基本数据类型 sizeof 功能【转】
转自:http://blog.csdn.net/sunboy_2050/article/details/7310008 版权声明:本文为博主原创文章,未经博主允许不得转载. Java基本数据类型int ...
- Java 基本数据类型 sizeof 功能
Java 基本数据类型 sizeof 功能 来源 https://blog.csdn.net/ithomer/article/details/7310008 Java基本数据类型int 32b ...
- JAVA使用SizeOf
研究一下JAVA的SizeOf 引用外部类实现JAVA的SizeOf JAVA本身是没有SizeOf的,因此我们需要去MavenRepository中下载JAR包(也可以使用maven等),因为这里只 ...
- 关于java中sizeof的问题
因为java没有提供现成的函数去计算对象的内存空间,不过可以用大量产生某个对象然后计算平均值的方法近似获得该对象占用的内存. 虽然这种方法不是很准,但是也在一定程度上计算出来了对象所占用的内存空间,下 ...
- 二叉树的创建和遍历(C版和java版)
以这颗树为例:#表示空节点前序遍历(根->左->右)为:ABD##E##C#F## 中序遍历(左->根->右)为:#D#B#E#A#C#F# 后序遍历(左->右-> ...
- AVL树原理及实现(C语言实现以及Java语言实现)
欢迎探讨,如有错误敬请指正 如需转载,请注明出处http://www.cnblogs.com/nullzx/ 1. AVL定义 AVL树是一种改进版的搜索二叉树.对于一般的搜索二叉树而言,如果数据恰好 ...
- iOS and JAVA 的 RSA 加密解密 (转载整理 )
参考原文地址:http://www.cnblogs.com/makemelike/articles/3802518.html (至于RSA的基本原理,大家可以看 阮一峰的网络日志 的 RSA算法原理( ...
随机推荐
- Sql三种分页方法
--分页三种方法--第一种 ROW_NUMBER() OVER( ORDER BY OrgID) AS indexs 大于pagesize*pageindex,少于等于pagesize*(pagein ...
- Extjs4使用iframe注意事项
"video" : { render : function(panel, eOpts) { // 因为iframe在video // panel渲染的时候就已经完全移动到video ...
- JDBC向oracle插入数据
public static void main(String[] args) throws SQLException { 2 3 4 String driver="oracle.jdbc.d ...
- Ext.Net学习笔记20:Ext.Net FormPanel 复杂用法
Ext.Net学习笔记20:Ext.Net FormPanel 复杂用法 在上一篇笔记中我们介绍了Ext.Net的简单用法,并创建了一个简单的登录表单.今天我们将看一下如何更好是使用FormPanel ...
- jquery load
$('#loadFooter').click(function() { $('#footer').load('footer.html'); });
- 解决VS2012【加载......符号缓慢】的问题
http://blog.csdn.net/shi0090/article/details/19411777 最近在用VS2012调试时,经常出现"加载......符号缓慢的问题", ...
- Spring框架中的单例Beans是线程安全的么?
Spring框架并没有对单例bean进行任何多线程的封装处理.关于单例bean的线程安全和并发问题需要开发者自行去搞定.但实际上,大部分的Spring bean并没有可变的状态(比如Serview类和 ...
- HDU 3943 K-th Nya Number(数位DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3943 题目大意:求出区间 (P,Q] 中找到第K个满足条件的数,条件是该数包含X个4和Y个7 Samp ...
- Basic MSI silent install
Articles and post about silent install for Basic MSI, InstallScript, InstallScript MSI: Silent-mode ...
- bzoj 1066: [SCOI2007] 蜥蜴
这道题还是挺好想的,但我一开始还是想错了…… 把每个石柱拆成两个点,一个入度,一个出度,两个点连一条容量为高度的边,这样就可以限制从此石柱上经过的蜥蜴的数量.关于蜥蜴是否单独成点,我是单独当成了一个点 ...