structDelete doesn't effect the shallow copy?
        Posted  
        
            by Travis
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Travis
        
        
        
        Published on 2010-06-15T02:22:11Z
        Indexed on 
            2010/06/15
            2:22 UTC
        
        
        Read the original article
        Hit count: 272
        
coldfusion
I was playing around onError so I tried to create an error using a large xml document object.
<cfset variables.XMLByRef = variables.parsedXML.XMLRootElement.XMLChildElement>
<cfset structDelete(variables.parsedXML, "XMLRootElement")>
<cfset variables.startXMLShortLoop = getTickCount()>
<cfloop from = "1" to = "#arrayLen(variables.XMLByRef)#" index = "variables.i">
  <cfoutput>#variables.XMLByRef[variables.i].id.xmltext#</cfoutput><br />
</cfloop>
<cfset variables.stopXMLShortLoop = getTickCount()>
I expected to get an error because I deleted the structure I was referencing.
From LiveDocs:
Variable Assignment - Creates an additional reference, or alias, to the structure. Any change to the data using one variable name changes the structure that you access using the other variable name. This technique is useful when you want to add a local variable to another scope or otherwise change a variable's scope without deleting the variable from the original scope.
instead I got
580df1de-3362-ca9b-b287-47795b6cdc17
25a00498-0f68-6f04-a981-56853c0844ed
... ... ...
db49ed8a-0ba6-8644-124a-6d6ebda3aa52
57e57e28-e044-6119-afe2-aebffb549342
Looped 12805 times in 297 milliseconds
<cfdump var = "#variables#">
Shows there's nothing in the structure, just parsedXML.xmlRoot.xmlName with the value of XMLRootElement. I also tried
<cfset structDelete(variables.parsedXML.XMLRootElement, "XMLChildElement")>
as well as structClear for both.
More information on deleting from the xml document object. http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-78e3.html
Can someone please explain my faulty logic? Thanks.
© Stack Overflow or respective owner