coldfusion - Does VAR scope in function really get Garbage collected quickly if the reference is shared? -


if have function say

<cfcomponent name="details"> <cffunctiion  name="getdetails" access="public" returntype="struct"> <cfscript> var mydetails = {}; mydetails.fname='lilly'; mydetails.lname ='flower'; </cfscript> <cfreturn mydetails > </cffunction> </cfcomponent> 

now call function , return session variable

<cfset session.mydetails = details.getdetails()> 

what here reference of structure mydetails (since complex object) function. believe reference point same memory location created when called function , variable created inside it.

so var scope garbage collected since have reference still pointing memory location through new session.mydetails variable!!!

when return value object, it's not returned reference. try this:

testcomponent.cfc

<cfcomponent name="details">      <cffunction  name="getdetails" access="public" returntype="struct">         <cfscript>             var mydetails = {};             mydetails.fname='lilly';             mydetails.lname ='flower';             mydetails.timestamp = gettickcount();         </cfscript>          <cfreturn mydetails />      </cffunction>  </cfcomponent> 

test.cfm

<cfset myobject = createobject("component", "testcomponent") /> <cfset mydetails = myobject.getdetails() /> <cfdump var="#mydetails#" label="first request" /> <cfset otherdetails = myobject.getdetails() /> <cfdump var="#mydetails#" label="after second request" /> <cfdump var="#otherdetails#" label="otherdetails second request" /> 

you'll notice first , second dumps mydetails same, means second request, variable set "otherdetails" not change original value in "mydetails". means structure returned, , assigned variable, byvalue instead of byreference.

with being said, original local variable in component should garbage collected @ same time component instance itself, while struct sitting in session won't garbage collected until session does.


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -