However, if any of said components can be modified, then they'll need
to be locked.

Here's a very trimmed down example of a memory leak that I still don't
understand...  (excuse syntax errors, i've never run this code)... I
don't know why the JRE can't handle it, but it can't. Look at the
method: "getArray ()" If I simply return this.theArray, it causes jrun
to become extremely unstable and it will eventually fail to return any
pages, or even errors. It will simply stop responding to requests and
the jrun process seems to hang. If I return: duplicate
(this.theArray), my server stabilizes and returns back to normal...
always responding to requests.

It makes me completely rethink how I'm passing arrays around. Could
there be other leaks in my code?

<!--------------------- define the component ("theCFC")
------------------->
<cfcomponent name="theCFC">

<cfset this.theArray = ArrayNew (1)>

<cffunction name="getArray" access="public" output="no"
returnType="Array">
   <cfreturn this.theArray> <!--- return using: duplicate
(this.theArray); solves the problem - JRE and server become stable
again --->
</cffunction>

<cffunction name="init" access="public" output="no"
returntype="theCFC">

   <!--- generate an array of structs with nested arrays of structs ---
>

   <cfloop from="1" to="1000" index="ix">
      <cfset s1 = StructNew ()>
      <cfset s1.ix = ix>
      <cfset s1.theArray = ArrayNew (1)>
      <cfloop from="1" to="1000" index="ixx">
            <cfset s2 = StructNew ()>
            <cfset s2.ix = ixx;
            <cfset s2.name = "this is #ixx#">
            <cfset ArrayAppend (s1.theArray, s2)>
      </cfloop>
      <cfset ArrayAppend (this.theArray, s1)>
   </cfloop>

   <cfreturn this />

</cffunction>

</cfcomponent>

<!------------------- somewhere to initialize -------------------------
>
<cflock scope="application" type="exclusive" throwontimeout="true"
timeout="30">
   <cfset Application.theCFC = createObject ("component",
"theCFC").init ()>
</cflock>

<!------------------- the caller creates the memory leak
-------------------->

<cflock scope="application" type="readonly" throwontimeout="true"
timeout="30">
   <cfset theArray = Application.theCFC.getArray ()>
</cflock>

<!--- use the array for whatever - somehow JRE GC loses track of local
var "theArray" --->

MEMORY LEAK




On Feb 11, 8:18 pm, Brian Kotek <[email protected]> wrote:
> As long as you var-scope any method-local variables, and the CFC doesn't
> have any instance data (data in the variable or this scope) changed during
> the method calls, you don't need to lock these.
>
> On Tue, Feb 9, 2010 at 5:06 PM, redtopia <[email protected]> wrote:
> > I'm using the Application scope to cache "type information" about the
> > various database objects in my application in order to speed up
> > database access. Each type has a corresponding "type handler" cfc that
> > does all the getting/setting/deleting of a specific type of object in
> > the database.
>
> > At first, I was creating the "type handler" cfc object (using
> > createObject ()) every time I wanted to access a database object, but
> > I found that createObject is very slow. Now I create the "type
> > handler" object once and store it in the "type information" that is
> > cached in the Application scope. So the "type handler" cfc's are now
> > being cached after I create it.
>
> > In order to avoid having to lock my application scope for the entire
> > time it takes to access the database, I lock the application scope,
> > copy the "type handler" cfc to the caller's scope using the duplicate
> > () function, and then make method calls into the copied version of the
> > "type handler" cfc.
>
> > Is there a better way to do this?
>
> > I've got a several other instances where I'm unsure about the best
> > method for accessing data and cfc's that are cached in the Application
> > scope without having to lock everything all the time. Another example
> > is that I create a siteMap cfc object that contains a hierarchical
> > array-based structure that is accessed on just about every request. I
> > do things like... display links to pages within the current section of
> > the site. I've got a method called "getSiteMapArray ()" that returns
> > the site map array. I haven't been calling the Duplicate () function
> > on the array before returning it... does anyone know if that might be
> > a source of a memory leak?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "CFCDev" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<cfcdev%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/cfcdev?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"CFCDev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cfcdev?hl=en.

Reply via email to