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的更多相关文章

  1. 数据库数据在Java占用内存简单估算

    数据库数据在Java占用内存简单估算 结论: 1.数据库记录放在JAVA里,用对象(ORM一般的处理方式)须要4倍左右的内存空间.用HashMap这样的KV保存须要10倍空间; 2.假设你主要数据是t ...

  2. Spark案例分析

    一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  3. Java 基本数据类型 sizeof 功能【转】

    转自:http://blog.csdn.net/sunboy_2050/article/details/7310008 版权声明:本文为博主原创文章,未经博主允许不得转载. Java基本数据类型int ...

  4. Java 基本数据类型 sizeof 功能

    Java 基本数据类型 sizeof 功能 来源 https://blog.csdn.net/ithomer/article/details/7310008 Java基本数据类型int     32b ...

  5. JAVA使用SizeOf

    研究一下JAVA的SizeOf 引用外部类实现JAVA的SizeOf JAVA本身是没有SizeOf的,因此我们需要去MavenRepository中下载JAR包(也可以使用maven等),因为这里只 ...

  6. 关于java中sizeof的问题

    因为java没有提供现成的函数去计算对象的内存空间,不过可以用大量产生某个对象然后计算平均值的方法近似获得该对象占用的内存. 虽然这种方法不是很准,但是也在一定程度上计算出来了对象所占用的内存空间,下 ...

  7. 二叉树的创建和遍历(C版和java版)

    以这颗树为例:#表示空节点前序遍历(根->左->右)为:ABD##E##C#F## 中序遍历(左->根->右)为:#D#B#E#A#C#F# 后序遍历(左->右-> ...

  8. AVL树原理及实现(C语言实现以及Java语言实现)

    欢迎探讨,如有错误敬请指正 如需转载,请注明出处http://www.cnblogs.com/nullzx/ 1. AVL定义 AVL树是一种改进版的搜索二叉树.对于一般的搜索二叉树而言,如果数据恰好 ...

  9. iOS and JAVA 的 RSA 加密解密 (转载整理 )

    参考原文地址:http://www.cnblogs.com/makemelike/articles/3802518.html (至于RSA的基本原理,大家可以看 阮一峰的网络日志 的 RSA算法原理( ...

随机推荐

  1. C# 批量插入表SQLSERVER SqlBulkCopy往数据库中批量插入数据

    #region 帮助实例:SQL 批量插入数据 多种方法 /// <summary> /// SqlBulkCopy往数据库中批量插入数据 /// </summary> /// ...

  2. C# 打印文件

    这几天做的功能用到了打印这个功能,直接在网上找了点demo,在这里做个备份. 1.直接打印DataTable using System; using System.Collections.Generi ...

  3. list,tuple,dict,字符串常用知识总结

    创建列表 sample_list = ['a',1,('a','b')] Python 列表操作 sample_list = ['a','b',0,1,3] 得到列表中的某一个值 value_star ...

  4. xmlDoc.SelectNodes用法(获取不到节点时注意事项)

    注:以下举例仅针对xml自定义了命名空间的情况,如果是其他情况,请参照他人博客~ using System;using System.Collections.Generic;using System. ...

  5. asp:第三平台登陆

    第三平台登陆接口申请网址: http://open.51094.com/ 文档: 第三方合作登录平台使用说明 为方便更多的开发朋友,本人特将当前市面上所有支持第三方联合登录的接口集为一体,以前需要多次 ...

  6. Java实战之04JavaWeb-08文件上传与下载

    一.文件上传 1.文件上传的实质是什么 文件的拷贝,文件从客户端拷贝服务器端 2.文件上传的工作 (1)客户端怎样将本地文件输出去? 1)文件上传的表单项 <input type=”file”& ...

  7. OpenJudge/Poj 2105 IP Address

    1.链接地址: http://poj.org/problem?id=2105 http://bailian.openjudge.cn/practice/2105 2.题目: IP Address Ti ...

  8. mysql常见的hint(转载的)

    mysql常用的hint对于经常使用oracle的朋友可能知道,oracle的hint功能种类很多,对于优化sql语句提供了很多方法.同样,在mysql里,也有类似的hint功能.下面介绍一些常用的. ...

  9. Chrome 将默认不播放非重要 Flash 内容

    Chrome 45将不再自动播放Flash,可能是45以后的版本都不自动播放了,没有具体测试. 小尺寸flash不被chrome播放,需要手动点击才能播放如何解决: <p>1.同域名fla ...

  10. python(二)基础

    1.lambda表达式(一般格式为冒号前边是参数冒号后边是返回值) 单参数: 多参数: 我们如果实现一个普通的filter过滤函数过滤掉偶数: 而我们如果用lambda表达式就很简便: 2.递归 普通 ...