Wednesday May 31, 2006 Testing memory leaks with assertGC
I was talking about assertSize in one of previous entry about testing. NbTestCase class contains more useful methods. Today I will be talking about assertGC method. The assertGC method tests tries to run garbage collect with different methods and then scan if exists path to reference in memory by using insane library. Look at simple example:
public class LeakTest extends NbTestCase {
public LeakTest(java.lang.String testName) {
super(testName);
}
public void testLeak() {
String obj = new String("test1");
WeakReference ref = new WeakReference(obj);
obj = null;
assertGC("pass",ref);
obj = new String("test2");
ref = new WeakReference(obj);
assertGC("fails",ref);
}
public static Test suite() {
TestSuite suite = new NbTestSuite(LeakTest.class);
return suite;
}
}
First asertGC passed because in JVM exists only WeakReference for object String("test1"). The second assertGC failed because the reference obj holds String("test2").
Posted by xzajo ( May 31 2006, 02:46:35 PM CEST ) Permalink Comments [16]
It would be nice to see who's holding a reference to what objects before and after a GC. Or, even better; do a GC, make a marking point, do some work, do several GC's (for finalizers), then report any new object references created in the "do some work" step.
And, how does INSANE or assertGC() deal with objects with finalizers and objects which may be queued up in the finalizer queue, (i.e. take more than 1 GC to be collected) ?
Posted by huntch on June 05, 2006 at 08:54 PM CEST #
Posted by Klaus Meffert on June 08, 2006 at 10:56 AM CEST #
public static void assertGC(String text, Reference<?> ref, Set<?> rootsHint) { List<byte[]> alloc = new ArrayList<byte[]>(); int size = 100000; for (int i = 0; i < 50; i++) { if (ref.get() == null) { return; } System.gc(); System.runFinalization(); try { alloc.add(new byte[size]); size = (int)(((double)size) * 1.3); } catch (OutOfMemoryError error) { size = size / 2; } try { if (i % 3 == 0) Thread.sleep(321); } catch (InterruptedException t) { // ignore } } alloc = null; fail(text + ":\n" + findRefsFromRoot(ref.get(), rootsHint)); }Posted by xzajo on June 08, 2006 at 01:53 PM CEST #
Posted by Klaus Meffert on June 08, 2006 at 05:50 PM CEST #
assertNotNull(ref)
Posted by xzajo on June 09, 2006 at 03:06 PM CEST #
Posted by 水无痕 on July 21, 2007 at 06:48 AM CEST #
<a href="http://www.feelingame.com/">wow power leveling</a>
<a href="http://www.feelingame.com">wow powerleveling</a>
<a href="http://www.cheap-wow-power-leveling.com">cheap wow power leveling</a>
<a href="http://www.cheap-wow-power-leveling.com/">wow power leveling</a>
<a href="http://www.cheap-wow-power-leveling.com/">wow powerleveling</a>
<a href="http://www.cheap-wow-power-leveling.com/">wow power lvl</a>
Posted by 00000000 on August 22, 2007 at 09:21 AM CEST #
http://www.bjseek.com.cn
http://www.bjxlzx.cn
http://www.sense.com.cn
http://jglsx.blog.sohu.com/
http://blog.china.alibaba.com/blog/jglsx.html
http://jglsx.blog.hexun.com/
http://tw.netsh.com/eden/blog/ctl_eden_blog.php?iBlogID=2610970
http://tw.netsh.com/eden/blog/ctl_eden_blog.php?iBlogID=2632783
http://blog.soufun.com/blog_12178456.html
http://blog.china-pub.com/blog.asp?name=jlb148140960
http://www.phpchina.com/38743
http://hexun.com/jglsx/default.html
http://www.xiongcaocao.com/?sid=116
http://jlb999.blog.163.com/
http://jjllbb.eomoo.com/user18/jlb148140960/index.shtml
http://hexun.com/xicao1/default.html
http://hexun.com/xicao3/default.html
http://hexun.com/xicao6/default.html
http://hexun.com/xicao9/default.html
http://hexun.com/xicao2/default.html
http://hexun.com/xicao7/default.html
http://hexun.com/xicao4/default.html
http://hexun.com/xicao5/default.html
http://hexun.com/xicao8/default.html
http://hexun.com/zwwsl/default.html
http://xicao6.blog.hexun.com/
http://xicao7.blog.hexun.com/
http://xicao8.blog.hexun.com/
http://xicao9.blog.hexun.com/
http://zwwsl.blog.hexun.com/
http://xicao1.blog.hexun.com/
http://xicao2.blog.hexun.com/
http://xicao3.blog.hexun.com/
http://xicao4.blog.hexun.com
http://xicao5.blog.hexun.com
http://tzgoogle.blog.hexun.com
http://hexun.com/tzgoogle/default.html
http://blog.ccidnet.com/blog-htm-uid-71265.html
http://hexun.com/baom/default.html
http://baom.blog.hexun.com
Posted by 数据恢复 on January 29, 2008 at 08:48 AM CET #
http://www.wowgolds.co.uk wow gold http://www.wowgolds.co.uk cheap wow gold http://www.wowgolds.co.uk buy wow gold http://www.wowgolds.co.uk world of warcraft gold http://www.wowgolds.co.uk wow http://www.wowgolds.co.uk world of warcraft http://www.wowgolds.co.uk/wow-gold.html wow gold http://www.wowgolds.co.uk/warrior.html WoW Warrior http://www.wowgolds.co.uk/hunter.html WoW Hunter http://www.wowgolds.co.uk/rogue.html WoW Rogue http://www.wowgolds.co.uk/paladin.html WoW Paladin http://www.wowgolds.co.uk/shaman.html WoW Shaman http://www.wowgolds.co.uk/priest.html WoW Priest http://www.wowgolds.co.uk/mage.html WoW Mage http://www.wowgolds.co.uk/druid.html WoW Druid http://www.wowgolds.co.uk/warlock.html WoW Warlock http://www.powerleveling2.cn power leveling http://www.powerleveling2.cn powerleveling http://www.wowpowerleveling2.cn wow power leveling http://www.wowpowerleveling2.cn wow powerleveling http://www.wowpro.cn wow guides http://www.wowmmo.cn wow tips http://ggtop.nbatop.com google排名 http://ggtop.nbatop.com google左侧排名 http://ggtop.nbatop.com google排名服务 http://www.baidupaiming.net 百度推广 http://www.baidupaiming.net 百度排名 http://www.fzqsnet.cn 网站推广 http://www.thebiz8.com 商业吧 http://www.thebiz8.com/jichuang.html 机床 http://www.thebiz8.com/leddeng.html LED灯 http://www.thebiz8.com/dianchi.html 电池 http://www.thebiz8.com/suliao.html 塑料 http://www.thebiz8.com/shexiangji.html 摄像机 http://www.thebiz8.com/yimin.html 移民 http://www.thebiz8.com/jiachun.html 甲醇 http://www.thebiz8.com/ranliao.html 染料 http://www.0591qs.cn 福州热线 http://www.sportblog.org.cn 体育博客 http://www.stockblog.org.cn 股票博客 http://www.gameblog.org.cn 游戏博客 http://www.cheap-wow-gold.org.cn 魔兽博客 http://www.excamtest.cn 考试博客 http://www.carblog.org.cn 汽车博客 http://www.houseblog.org.cn 房产博客 http://www.pcblog.org.cn 电脑博客 http://powerlin518.iblog.com powerlin518 http://www.xcelwebdesign.com logo design http://www.xcelwebdesign.com website design http://www.xcelwebdesign.com web design http://www.shangbiaodesign.cn 商标设计
Posted by power leveling on March 20, 2008 at 04:39 PM CET #
<a href="http://blog.tyfo.com/?U=banjiagg" rel="nofollow">搬家公司</a>
<a href="http://blog.tyfo.com/?U=banjiagg">搬家公司</a>
Posted by hrz on April 06, 2008 at 09:06 AM CEST #
<a href="http://blog.tyfo.com/?U=banjiagg" rel="nofollow">搬家公司</a>
<a href="http://blog.tyfo.com/?U=banjiagg">搬家公司</a>
Posted by hrz on April 06, 2008 at 09:07 AM CEST #
<a href="http://blog.tyfo.com/?U=banjiagg" rel="nofollow">搬家公司</a>
<a href="http://blog.tyfo.com/?U=banjiagg">搬家公司</a>
<a href="http://www.hrzbq.com">深圳搬家公司</a>
Posted by hrz on April 06, 2008 at 09:08 AM CEST #
Landseer
Posted by wow gold on October 27, 2008 at 01:31 AM CET #
you can buy cheap wow gold.
Posted by wow gold on October 27, 2008 at 01:32 AM CET #
buy warhammer gold.
Landseer
Posted by Warhammer gold on October 27, 2008 at 01:34 AM CET #
http://sunnyren.weblog.com/
this blog introduces jewelry products and fashion jewelry
Posted by fashion jewelry on October 31, 2008 at 06:50 AM CET #