<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LoadRunner TnT &#187; memory leaks</title>
	<atom:link href="http://www.loadrunnertnt.com/tag/memory-leaks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.loadrunnertnt.com</link>
	<description>Performance Testing, LoadRunner Tips &#38; Tricks</description>
	<lastBuildDate>Mon, 08 Mar 2010 07:57:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Achieving High Performance Application in Java Coding!</title>
		<link>http://www.loadrunnertnt.com/coding/achieving-high-performance-application-in-java-coding/</link>
		<comments>http://www.loadrunnertnt.com/coding/achieving-high-performance-application-in-java-coding/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 07:20:14 +0000</pubDate>
		<dc:creator>TnT Admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[memory leaks]]></category>
		<category><![CDATA[optimizing]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[substring]]></category>

		<guid isPermaLink="false">http://www.loadrunnertnt.com/?p=620</guid>
		<description><![CDATA[High performance web sites and applications can start from the design coding level.  Most of the time, performance tuning we view comes at the later stage of the development life cycle, in particular at the deployment stage.  What can we do by deployment stage?  We can only tune start up parameters, add more hardware, or [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.loadrunnertnt.com/wp-content/uploads/2010/01/web_coding_collage.jpg"><img class="alignleft size-thumbnail wp-image-633" title="web_coding_collage" src="http://www.loadrunnertnt.com/wp-content/uploads/2010/01/web_coding_collage-150x150.jpg" alt="" width="86" height="86" /></a>High performance web sites and applications can start from the design coding level.  Most of the time, performance tuning we view comes at the later stage of the development life cycle, in particular at the deployment stage.  What can we do by deployment stage?  We can only tune start up parameters, add more hardware, or add more network components in the architecture.  But what if the problem is in the JVM where you diagnose it to be poor application performance due to coding?  Changing codes at this stage will be more expensive and difficult unlike when you are in the development stage!<span id="more-620"></span></p>
<p>How can we build a high performance web site through coding then?  Here are some basic tips you should note during development which should not be a big hassle for you to make changes anytime!<strong> </strong></p>
<p><strong>1. Remove any unused      variables – </strong>The first thing and most simple thing you can do is to avoid      creating unused variables.  Use      static code analysers and look for variables that are initialized but not      used.  Sometimes, in the midst of      development, we leave out variables that aren’t used anymore and this can      be removed to converse memory.<strong></strong></p>
<p><strong>2. Free all resources – </strong>All created resources      and variables should be released once they are not used.  This helps converse memory.  This will help optimize the memory usage      and thus reduce the need for garbage collection cycle to take place.  Resources such as database connections      and files are simple examples that you should close and release the      resources.<strong></strong></p>
<p><strong>3. Free all resources in      the ‘finally’ block – </strong>Similar to [2], we want to free all      resources.  However, this is catered      to “unhappy” flow of the program code.       Free all resources that are used when exception arises if applicable.<strong></strong></p>
<p><strong>4. Avoid calling methods in loops – </strong>This can be circumvented when the compiler optimizes the code.  However, if it doesn’t the loop condition will be calculated for each iteration during the loop</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// bad practise</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MethodInLoop <span style="color: #009900;">&#123;</span><br />
<span style="color: #000066; font-weight: bold;">void</span> method <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Avector+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Vector</span></a> vector<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> vector.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">// do something</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// good practise</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MethodOutOfLoop <span style="color: #009900;">&#123;</span><br />
<span style="color: #000066; font-weight: bold;">void</span> method <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Avector+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Vector</span></a> vector<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000066; font-weight: bold;">int</span> size <span style="color: #339933;">=</span> vector.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">// do something</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p><strong>5. Avoid methods that may      cause memory leaks – </strong>Methods such as split(java.lang.String),      split(java.lang.String, int), substring(int), substring(int,int),      nextElement(), nextToken(), nextToken(java.lang.String), group() and      group(int) are candidates of memory leak.       There are quite a fair bit of search results on the methods that      causes memory leaks.  You can refer      to <a href="http://eyalsch.wordpress.com/2009/10/27/stringleaks/">“Strings      and Memory Leaks”</a> from The Java Explorer for some information.  Avoid such methods whenever      possible.  If not, do use it with      care.</p>
<p>More to come on coding for high performance applications!  Share with us on your performance coding tips here too! <img src='http://www.loadrunnertnt.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.loadrunnertnt.com/coding/achieving-high-performance-application-in-java-coding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
