<?xml version="1.0" encoding="utf-8"?>
			
			<rss version="2.0">
			<channel>
			<title>Mike Schierberl&apos;s Blog - memory</title>
			<link>http://www.schierberl.com/cfblog/index.cfm</link>
			<description>Mike Schierberl&apos;s thoughts on software development and coldfusion</description>
			<language>en-us</language>
			<pubDate>Sun, 05 Sep 2010 12:52:08 -0700</pubDate>
			<lastBuildDate>Wed, 25 Oct 2006 16:15:00 -0700</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>mike@schierberl.com</managingEditor>
			<webMaster>mike@schierberl.com</webMaster>
			
			
			
			
			
			<item>
				<title>Memory Leaks: Part III - sessions and cfcs</title>
				<link>http://www.schierberl.com/cfblog/index.cfm/2006/10/25/memoryLeaks_session</link>
				<description>
				
				&amp;nbsp;&amp;nbsp;&amp;nbsp; In part III of my memory leak posts, I will attempt to show an example of how variable references can increase within in the heap on every request. If you would like to know more about the tools I used to identify the problem, or would like to follow along with the example you should take a look at my previous posts, &lt;br /&gt;
&lt;a href=&quot;../../../index.cfm/2006/10/12/ColdFusion_memoryLeak_profiler&quot;&gt;&amp;quot;ColdFusion Memory Leaks: Part I - profiler introduction&amp;quot;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.schierberl.com/cfblog/index.cfm/2006/10/16/memoryLeak_variablesScope&quot;&gt;&amp;quot;ColdFusion Memory Leaks: Part II - variables scope&amp;quot;&lt;/a&gt;&lt;br /&gt;
&lt;font color=&quot;#ff0000&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Note:&amp;nbsp; The example that I will demonstrate is 90% complete.&amp;nbsp; It is similar to the behavior that I experienced in my application, but not as severe.&amp;nbsp; This only works in specific circumstances, where my problem appeared 100% of the time.&amp;nbsp; Unfortunately, this is the closest I could come without including hundreds of thousands of lines of code.&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
For this example, we will expand the case that I demonstrated in the variables scope example.&amp;nbsp; We will use the same test.cfc as the previous example.&lt;br /&gt;
&lt;code&gt;&lt;!--- file: test.cfc ---&gt;
&lt;cfcomponent name=&quot;test&quot;&gt;   
   &lt;cffunction name=&quot;init&quot;&gt;
      &lt;cfreturn this &gt;
   &lt;/cffunction&gt;
   
   &lt;cffunction name=&quot;doSomething&quot;&gt;
      &lt;cfset var idx = &quot;&quot; /&gt;
      &lt;cfset var arrayToReturn = arrayNew(1) /&gt;
      &lt;cfloop from=&quot;1&quot; to=&quot;100&quot; index=&quot;idx&quot;&gt;
         &lt;cfset arrayAppend(arrayToReturn,createObject(&quot;component&quot;,&quot;test&quot;).init()) /&gt;
      &lt;/cfloop&gt;
      &lt;cfreturn arrayToReturn &gt;
   &lt;/cffunction&gt;
&lt;/cfcomponent&gt;&lt;/code&gt; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Next we will need to expand the cfm page, we&apos;ll make the following modifications.&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;add session timeout of 10 seconds (to see results quickly)&lt;/li&gt;
    &lt;li&gt;only load test.cfc into application on the first request&lt;/li&gt;
    &lt;li&gt;create an array on the session&lt;/li&gt;
    &lt;li&gt;create a new instance of test.cfc locally, and append it to the array on the session&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;code&gt;&lt;!--- file: test.cfm ---&gt;
&lt;cfapplication name=&quot;memoryTest&quot; sessionmanagement=&quot;true&quot; sessiontimeout=&quot;#createTimeSpan(0,0,0,10)#&quot; &gt;

&lt;!--- create an instance of test.cfc in application, adding reset to the URL, will cleanup all references ---&gt;
&lt;cfif not structKeyExists(application,&quot;test&quot;) OR isDefined(&quot;URL.reset&quot;)&gt; 
	&lt;cfset application.test = createObject(&quot;component&quot;,&quot;test&quot;).init() /&gt;
	&lt;cflocation url=&quot;#cgi.SCRIPT_NAME#&quot; addtoken=&quot;false&quot;&gt;
&lt;/cfif&gt;

&lt;cfset foo = application.test.doSomething() /&gt;

&lt;cfif not structKeyExists(session,&quot;sessionArray&quot;)&gt;
	&lt;cfset session.sessionArray = arrayNew(1)&gt;
	creating a new session&lt;br /&gt;
&lt;/cfif&gt;

&lt;cfset objectToPutInSession = createObject(&quot;component&quot;,&quot;test&quot;) &gt;

&lt;cfset arrayAppend(session.sessionArray,objectToPutInSession)&gt;

completed request - session size = &lt;cfoutput&gt;#arrayLen(session.sessionArray)#&lt;/cfoutput&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;cfoutput&gt;&lt;a href=&quot;#cgi.SCRIPT_NAME#?reset=true&quot;&gt;reset application.test (this clears all memory references)&lt;/a&gt;&lt;/cfoutput&gt; &lt;/code&gt;  What should we expect in this example? (feel free to correct me if you think this should be different)&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;1 instance of test.cfc should be loaded into application&lt;/li&gt;
    &lt;li&gt;foo exists in variables scope and creates a reference to an array of 100 instances of test.cfc (this is the example from Part II and should be destroyed at the end of the request)&lt;/li&gt;
    &lt;li&gt;an instance of test.cfc will be added to the session on every request. (5 request in a session = 5 test.cfc)&lt;/li&gt;
    &lt;li&gt;when the session expires, the array should be cleaned from the heap.&lt;/li&gt;
&lt;/ul&gt;
Now for a flash movie that will show the results of what actually happens (my apologies if this is rushed, there&apos;s quite a bit going on in a short timeframe)&lt;br /&gt;
&lt;div class=&quot;flash600obj&quot;&gt;  

&lt;mikeFlashObjectobject classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; codebase=&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0&quot; id=&quot;FLVPlayer&quot; height=&quot;312&quot; width=&quot;600&quot;&gt;    
&lt;param name=&quot;movie&quot; value=&quot;/cfblog/FLVPlayer_Progressive.swf&quot;&gt;    
&lt;param name=&quot;salign&quot; value=&quot;lt&quot;&gt;    
&lt;param name=&quot;quality&quot; value=&quot;high&quot;&gt;    
&lt;param name=&quot;scale&quot; value=&quot;noscale&quot;&gt;    
&lt;param name=&quot;FlashVars&quot; value=&quot;&amp;amp;MM_ComponentVersion=1&amp;amp;skinName=/cfblog/Clear_Skin_2&amp;amp;streamName=/cfblog/memLeakSession&amp;amp;autoPlay=false&amp;amp;autoRewind=false&quot;&gt;    &lt;mikeFlashObjectembed src=&quot;/cfblog/FLVPlayer_Progressive.swf&quot; flashvars=&quot;&amp;amp;MM_ComponentVersion=1&amp;amp;skinName=/cfblog/Clear_Skin_2&amp;amp;streamName=/cfblog/memLeakSession&amp;amp;autoPlay=false&amp;amp;autoRewind=false&quot; quality=&quot;high&quot; scale=&quot;noscale&quot; name=&quot;FLVPlayer&quot; salign=&quot;LT&quot; type=&quot;application/x-shockwave-flash&quot; pluginspage=&quot;http://www.macromedia.com/go/getflashplayer&quot; height=&quot;312&quot; width=&quot;600&quot;&gt;  &lt;/mikeFlashObjectobject&gt;  &lt;/div&gt;

&lt;br /&gt;
What happened??(also, how you can follow along if you execute the example)&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;On the first request, test.cfc is loaded into the application at the same time a new session is created&lt;/li&gt;
    &lt;li&gt;Every request loads an extra 100 references to test.cfc (which should only exist in variables scope)&lt;/li&gt;
    &lt;li&gt;The session that loads the cfc into application scope (and only this session) will persist all the references for the life of the application&lt;/li&gt;
    &lt;li&gt;All additional sessions will hold their references for the life of the session&lt;/li&gt;
    &lt;li&gt;Adding a structure to session instead of a cfc will create the proper behavior&lt;/li&gt;
&lt;/ul&gt;
&lt;font size=&quot;4&quot;&gt;Summary&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Why does this happen?&amp;nbsp; I can&apos;t tell you, I&apos;m hoping the community, or adobe will be able to figure that out.&amp;nbsp; Some other notes that I would like to add.... The behavior occurs if it is a struct OR an array on the session.&amp;nbsp; The behavior also occurs if all the cfcs are different (I used test.cfc for all references to keep the example simple).&amp;nbsp; If you reload application.test, the references will be cleaned up, but the behavior will occur for the session associated with the request that created application.test.&lt;br /&gt;
&lt;br /&gt;
&lt;font size=&quot;4&quot;&gt;How do I fix this in my application???&lt;/font&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; I am not going to recommend a solution for this because I haven&apos;t found a &amp;quot;magic bullet&amp;quot; yet.&amp;nbsp; I am also not going to recommend a solution because every application is unique, and every memory leak is different.&amp;nbsp; I will however tell you that my problem was very similar to this.&amp;nbsp; We were keeping a history stack on the session that consisted of an array of simple beans.&amp;nbsp; Converting the beans to structures, solved a large part of the problem.&amp;nbsp; This isn&apos;t always an option if you are storing complex objects on the session.&amp;nbsp; I&apos;m very interested to see if anyone else having a similar problem is storing cfcs on a session, as the root cause seems to be a wacky combination of instantiating cfcs on multiple scopes within a request.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
				
				</description>
						
				
				<category>memory</category>				
				
				<category>coldfusion</category>				
				
				<pubDate>Wed, 25 Oct 2006 16:15:00 -0700</pubDate>
				<guid>http://www.schierberl.com/cfblog/index.cfm/2006/10/25/memoryLeaks_session</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>Memory Leaks: Part II - variables scope leak</title>
				<link>http://www.schierberl.com/cfblog/index.cfm/2006/10/16/memoryLeak_variablesScope</link>
				<description>
				
				&amp;nbsp;&amp;nbsp;&amp;nbsp; In part II of my memory leak posts, I will attempt to demonstrate a simple example of how the CFML runtime engine can cause memory leaks.&amp;nbsp; If you would like to know more about the tools I used to identify the problem, or would like to follow along with the example you should take a look at my previous post,&amp;nbsp; &lt;a href=&quot;http://www.schierberl.com/cfblog/index.cfm/2006/10/12/ColdFusion_memoryLeak_profiler&quot;&gt;&amp;quot;ColdFusion Memory Leaks: Part I - profiler introduction&amp;quot;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; For those of you that have ever experienced memory leaks, have there been cases where you have been convinced that the problem is not your code?&amp;nbsp; Well, you may actually be right.&amp;nbsp; This example will show a very simple case, then I will try to build on this to show a more problematic example in my next post.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; The first part of the example is to create a simple .cfc.&amp;nbsp; This cfc will have 2 methods: init() which returns itself, and doSomething()&amp;nbsp; which will return an array of 100 instances of itself.&lt;br /&gt;
&lt;code&gt;&lt;!--- file: test.cfc ---&gt;
&lt;cfcomponent name=&quot;test&quot;&gt;	
	&lt;cffunction name=&quot;init&quot;&gt;
		&lt;cfreturn this &gt;
	&lt;/cffunction&gt;
	
	&lt;cffunction name=&quot;doSomething&quot;&gt;
		&lt;cfset var idx = &quot;&quot; /&gt;
		&lt;cfset var arrayToReturn = arrayNew(1) /&gt;
		&lt;cfloop from=&quot;1&quot; to=&quot;100&quot; index=&quot;idx&quot;&gt;
			&lt;cfset arrayAppend(arrayToReturn,createObject(&quot;component&quot;,&quot;test&quot;).init()) /&gt;
		&lt;/cfloop&gt;
		&lt;cfreturn arrayToReturn &gt;
	&lt;/cffunction&gt;
&lt;/cfcomponent&gt;&lt;/code&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;  The next part of the example will be a simple cfm file.&amp;nbsp; This file will create 1 instance of the test.cfc and load it into application scope, then it will call the doSomething() function and set the result to a local variable that resides in variables scope. &lt;br /&gt;
&lt;code&gt;&lt;!--- file: test.cfm ---&gt;
&lt;cfapplication name=&quot;memoryTest&quot;&gt;

&lt;cfset application.test = createObject(&quot;component&quot;,&quot;test&quot;).init() /&gt;

&lt;cfset foo = application.test.doSomething() /&gt;

&lt;cfoutput&gt;foo is an array of #arrayLen(foo)# elements&lt;/cfoutput&gt;&lt;/code&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; What should we expect from this example?&amp;nbsp; Well, we should have 1 instance of test.cfc persisted in the heap.&amp;nbsp; We will create 100 references to test.cfc, but those should only exist in the heap until the end of the request.&amp;nbsp; The garbage collector should pick them up immediately, as all references should only exist for the request.&lt;br /&gt;
&lt;br /&gt;
Now, to show the results of the test, I created a flash movie that will show the behavior,&amp;nbsp; watch it to see what actually happens.&lt;br /&gt;
&lt;div class=&quot;flash600obj&quot;&gt;
&lt;object classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; codebase=&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0&quot; width=&quot;600&quot; height=&quot;306&quot; id=&quot;FLVPlayer&quot;&gt;
  &lt;param name=&quot;movie&quot; value=&quot;/cfblog/FLVPlayer_Progressive.swf&quot; /&gt;
  &lt;param name=&quot;salign&quot; value=&quot;lt&quot; /&gt;
  &lt;param name=&quot;quality&quot; value=&quot;high&quot; /&gt;
  &lt;param name=&quot;scale&quot; value=&quot;noscale&quot; /&gt;
  &lt;param name=&quot;FlashVars&quot; value=&quot;&amp;MM_ComponentVersion=1&amp;skinName=/cfblog/Clear_Skin_2&amp;streamName=/cfblog/simple_Leak&amp;autoPlay=false&amp;autoRewind=false&quot; /&gt;
  &lt;embed src=&quot;/cfblog/FLVPlayer_Progressive.swf&quot; flashvars=&quot;&amp;MM_ComponentVersion=1&amp;skinName=/cfblog/Clear_Skin_2&amp;streamName=/cfblog/simple_Leak&amp;autoPlay=false&amp;autoRewind=false&quot; quality=&quot;high&quot; scale=&quot;noscale&quot; width=&quot;600&quot; height=&quot;306&quot; name=&quot;FLVPlayer&quot; salign=&quot;LT&quot; type=&quot;application/x-shockwave-flash&quot; pluginspage=&quot;http://www.macromedia.com/go/getflashplayer&quot; /&gt;
&lt;/object&gt;
&lt;/div&gt;


  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;font size=&quot;4&quot; color=&quot;#ff0000&quot;&gt; Results:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;What happened?&amp;nbsp; As you can see, 101 instances were persisted in the heap, and not released.&amp;nbsp; These instances will live for the life of the application and NOT for the life of the request as intended.&amp;nbsp; In this case we should only see 1 instance of the cfc in the heap. Here are some of the behaviors I observed. &lt;br / &gt; &lt;br / &gt; &lt;ol &gt; &lt;li &gt; references to objects created in application scope will be kept alive if they are
set to a reference in the variables scope. &lt;/li &gt; &lt;li &gt; Setting the variable in variables scope to empty string &amp;quot; &amp;quot; 
                      will destroy the reference. &lt;/li &gt; &lt;li &gt; Setting the reference in request scope will clean up the reference correctly. &lt;/li &gt; &lt;li &gt; Calling structClear(variables)
                       in onRequestEnd.cfm will destroy unwanted references tied to variables scope &lt;/li &gt; &lt;li &gt; The reference retained in the variables scope only seems
                       to apply to the last request to the.cfm file (will not grow) &lt;/li &gt; &lt;/ol &gt; &lt;font size = [4] color = [#ff0000] &gt; Summary : &lt;/font &gt; &lt;br / &gt; &amp;nbsp; 
                      &amp;nbsp;&amp;nbsp; As you can see, this isn &apos;t a horrible memory leak because it won&apos;t grow continually, 
                      but it could cause unwanted objects to be persisted in memory. &amp;nbsp; This IS a simple example, and 
                      I&apos;m working to create a similar, but more complex example to build on this that will show that cfc references can grow in memory on every request.&amp;nbsp; Stay Tuned.


				
				</description>
						
				
				<category>memory</category>				
				
				<category>coldfusion</category>				
				
				<pubDate>Mon, 16 Oct 2006 11:50:00 -0700</pubDate>
				<guid>http://www.schierberl.com/cfblog/index.cfm/2006/10/16/memoryLeak_variablesScope</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>ColdFusion Memory Leaks: Part I - profiler introduction</title>
				<link>http://www.schierberl.com/cfblog/index.cfm/2006/10/12/ColdFusion_memoryLeak_profiler</link>
				<description>
				
				Over the last year or so I&apos;ve been dealing with memory leaks in ColdFusion.&amp;nbsp; Some have been code related, but others seem to be issues with the way ColdFusion handles garbage collection of CFCs.&amp;nbsp; Recently, we&apos;ve made some breakthroughs at my company, so I thought I would share the steps that we took to identify memory leaks along with some interesting behaviors that we observed.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
Hopefully, when I am finished, you will be on your way to changing your memory profile to look something like this... (This is an actual application profile under load)&lt;br /&gt;
&lt;br /&gt;
&lt;table width=&quot;100%&quot; cellspacing=&quot;&quot; cellpadding=&quot;&quot; border=&quot;0&quot; align=&quot;&quot; summary=&quot;&quot;&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td align=&quot;center&quot;&gt;&amp;nbsp;&lt;img width=&quot;250&quot; height=&quot;156&quot; alt=&quot;&quot; src=&quot;/cfblog/images/UserFiles/Image/memoryBefore.jpg&quot; /&gt;&lt;br /&gt;
            Before&lt;/td&gt;
            &lt;td align=&quot;center&quot;&gt;&amp;nbsp;&lt;img width=&quot;250&quot; height=&quot;152&quot; alt=&quot;&quot; src=&quot;/cfblog/images/UserFiles/Image/memoryAfter.jpg&quot; /&gt;&lt;br /&gt;
            After&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
In this post, I will show you the steps that I used to setup an environment that enabled me to identify the problem.&lt;br /&gt;
&lt;br /&gt;
&lt;font size=&quot;4&quot; color=&quot;#3366ff&quot;&gt;Step 1:&lt;/font&gt;&lt;font color=&quot;#3366ff&quot;&gt;&amp;nbsp; configure your jvm: 5.0 is the way to go&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; The first thing that I tried was to use a profiling tool (i.e. jprobe or yourkit) against my existing coldfusion/jrun instance.&amp;nbsp; This proved to be a mistake because the profiler added so much overhead to the jvm that the application became unresponsive.&amp;nbsp; The solution was to use a Java 5 jvm.&amp;nbsp; Jrun does not support Java 5 (JVM 1.5), but for the most part your application should run to the point that you can profile effectively.&lt;br /&gt;
&lt;br /&gt;
&lt;font size=&quot;4&quot; color=&quot;#3366ff&quot;&gt;Step 2:&lt;/font&gt;&lt;font color=&quot;#3366ff&quot;&gt;&amp;nbsp; running with BEA Jrockit&lt;br /&gt;&lt;/font&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; For our example, I will suggest using the 1.5 jrockit jvm provided by BEA.&amp;nbsp; The reason for this is because they have some powerful profiling tools that I will talk about later.&lt;br /&gt;
&lt;br /&gt;
First, go to the following URL, and install the Jrockit 5.0 JDK&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://commerce.bea.com/products/weblogicjrockit/jrockit_prod_fam.jsp&quot; target=&quot;_blank&quot;&gt;http://commerce.bea.com/products/weblogicjrockit/jrockit_prod_fam.jsp&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font color=&quot;#ff0000&quot;&gt;(For the rest of the example I will assume that you installed the JDK at &lt;/font&gt;&lt;font color=&quot;#ff0000&quot;&gt;C:\Program_Files\Java\jrockit-R26.4.0-jdk1.5.0_06\ )&lt;br /&gt;&lt;/font&gt;
&lt;br /&gt;
you will also need to download a Jrockit Mission Control  1.0 license key. (you may need to register for that), save this file named as license.bea and move it to the following folder.&lt;br /&gt;
&lt;font color=&quot;#3366ff&quot;&gt;\jrockit-R26.4.0-jdk1.5.0_06\jre\&lt;br /&gt;
&lt;/font&gt;&lt;br /&gt;
&lt;font size=&quot;2&quot;&gt;After that, modify your jvm.config file and change java.home  to the following... (make sure to use forward slashes)&lt;br /&gt;
&lt;br /&gt;
&lt;/font&gt;&lt;font color=&quot;#3366ff&quot;&gt;java.home=C:/Program Files/Java/jrockit-R26.4.0-jdk1.5.0_06/jre&lt;br /&gt;
&lt;br /&gt;
&lt;/font&gt;to enable profiling, you will need to add the following to your jvm args... (specify any  port that you want)&lt;br /&gt;
&lt;br /&gt;
&lt;font color=&quot;#3366ff&quot;&gt;-Xmanagement -Djrockit.managementserver.port=9010&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
Now restart the CF service and you are  ready to go.&lt;br /&gt;
&lt;br /&gt;
&lt;font size=&quot;4&quot; color=&quot;#3366ff&quot;&gt;Step 3:&lt;/font&gt;&lt;font color=&quot;#3366ff&quot;&gt;&amp;nbsp; memory leak detector&lt;/font&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Now for the fun part... the Jrockit JDK ships with a tool called &amp;quot;Memory Leak Detector&amp;quot;, To start using this, browse to the following folder...&lt;br /&gt;
&lt;br /&gt;
&lt;font color=&quot;#3366ff&quot;&gt;C:\Program  Files\Java\jrockit-R26.4.0-jdk1.5.0_06\memleak&lt;br /&gt;
&lt;br /&gt;
&lt;/font&gt;Then double click on MemoryLeakDetector.jar (you may have to  run it from the command line if that doesn&apos;t work).&amp;nbsp; The tool should start, and  you should be able to specify the server and port (that you specified in  jvm.config).&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;img width=&quot;500&quot; height=&quot;275&quot; src=&quot;/cfblog/images/UserFiles/Image/jrockit_connect.gif&quot; alt=&quot;&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
The next step is critical to effectively profile a ColdFusion application.&amp;nbsp; From what I&apos;ve observed, Internally, most of your variable data will be stored within objects of type coldfusion.runtime.variable.&amp;nbsp; CFC classes don&apos;t hold much data, so they take up a very small percentage of the jvm heap.&amp;nbsp; We need to change the memory leak detector settings to look at small heap sizes.&amp;nbsp; To do this, browse to File/Preferences/Trend and change &amp;quot;lowest heap usage to report&amp;quot; to  0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img width=&quot;650&quot; height=&quot;173&quot; src=&quot;/cfblog/images/UserFiles/Image/memleak_lowestHeap.jpg&quot; alt=&quot;&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;font size=&quot;4&quot; color=&quot;#3366ff&quot;&gt;Step 4:&lt;/font&gt;&lt;font color=&quot;#3366ff&quot;&gt;&amp;nbsp; example&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
To show you how to use the memory leak detector, we will create an example, for this example I will create a cfc, this cfc has 2 methods, init() that returns itself, and doSomething() which will load 100 instances of itself into the variables scope of the object.&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;!--- file: test.cfc ---&gt;
&lt;cfcomponent name=&quot;test&quot;&gt;
	&lt;cfset variables.holderArray = arrayNew(1)&gt;
	
	&lt;cffunction name=&quot;init&quot;&gt;
		&lt;cfreturn this&gt;
	&lt;/cffunction&gt;
	
	&lt;cffunction name=&quot;doSomething&quot;&gt;
		&lt;cfset var idx = &quot;&quot;&gt;

		&lt;cfloop from=&quot;1&quot; to=&quot;100&quot; index=&quot;idx&quot;&gt;
			&lt;cfset arrayAppend(variables.holderArray) = createObject(&quot;component&quot;,&quot;test&quot;).init() /&gt;
		&lt;/cfloop&gt;
	&lt;/cffunction&gt;
&lt;/cfcomponent&gt;
&lt;/code&gt;
&lt;br&gt;
Next, create a simple cfm page that will load the cfc into memory and call the doSomething() function.&amp;nbsp; Calling this .cfm page should create 101 instances of test in the application scope (1 loaded into application, and 100 loaded within itself) &lt;br /&gt;
&lt;br /&gt;

&lt;code&gt;&lt;!--- file: test.cfm ---&gt;
&lt;cfapplication name=&quot;test&quot;&gt;

&lt;cfset application.test = createObject(&quot;component&quot;,&quot;test&quot;)&gt;

&lt;cfset application.test.doSomething()&gt;&lt;/code&gt;
After you have executed the page, return to your memory leak detector and &lt;font color=&quot;#ff0000&quot;&gt;&lt;strong&gt;filter by &amp;quot;cf&amp;quot; &lt;/strong&gt;&lt;font color=&quot;#000000&quot;&gt;(you can also filter by &amp;quot;cold&amp;quot; to see internal ColdFusion representations).&amp;nbsp; You should now see something like this in the memory leak detector.&lt;br /&gt;
&lt;img width=&quot;654&quot; height=&quot;360&quot; alt=&quot;&quot; src=&quot;/cfblog/images/UserFiles/Image/memoryLeakTest.gif&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
you will now see that we have created 101 instances of test.cfc in the memory heap (along with a reference to test.cfm that it is keeping alive, plus the empty classes it uses internally to identify the init() and doSomething() methods.&lt;br /&gt;
&lt;br /&gt;
&lt;font size=&quot;4&quot;&gt;Congratulations!&lt;br /&gt;
&lt;/font&gt; &lt;br /&gt;
If you have made it to this point, you are on your way to profiling your application.&amp;nbsp; If you leave the memory leak detector running under load, it will eventually track the growth of objects, and can be used to pinpoint potential problems. In my next post I will identify some of the potential problem behaviors of the ColdFusion engine, and how it can potentially &amp;quot;leak&amp;quot; object references in simple examples.&lt;br /&gt;
&lt;br /&gt;
&lt;font size=&quot;4&quot;&gt;Credits and Reading materials&lt;/font&gt;&lt;br /&gt;
The basis of this strategy is outlined in greater detail in a pdf book created by Grant Straker.&amp;nbsp; He focuses on other aspects of optimizing cf performance besides memory usage as well.&amp;nbsp; If you are headed to Max, then I would highly recommend checking out his talk.&lt;br /&gt;
&lt;br /&gt;
His pdf book is available at...&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.cfperformance.com/&quot;&gt;http://www.cfperformance.com/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In my opinion this could be the most valuable $50 that you will ever spend on CF knowledge, and is well worth the money.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
				
				</description>
						
				
				<category>memory</category>				
				
				<category>coldfusion</category>				
				
				<pubDate>Thu, 12 Oct 2006 17:55:00 -0700</pubDate>
				<guid>http://www.schierberl.com/cfblog/index.cfm/2006/10/12/ColdFusion_memoryLeak_profiler</guid>
				
			</item>
			
		 	
			</channel></rss>