Skip to main content
Inspiring
October 14, 2008
Question

Deleting a structure from an array

  • October 14, 2008
  • 1 reply
  • 335 views
I have an application where the use can step through a form to create a list of software. To make it easier reference the software name, ID and a few other fields are stored as a structure in each element of a one dimensional array like this:
<cfset sDetails = StructNew()>
<cfset sDetails.LicenceDetail_ID="">
<cfset sDetails.SoftwareID="#FORM.softwareID#">
<cfset sDetails.SoftwareName="#FORM.softwareName#">
<cfset ArrayAppend(SESSION.SoftwareArray, sDetails)>

My question is, how do I properly release this information from memory when I'm done with it? If it was a regular structure stored as a Session variable I would just delete it using this code.
<cfloop index="ListElement" list="#StructKeyList(SESSION.currentSoftware)#" delimiters=",">
<cfset StructDelete(SESSION.currentSoftware, "#ListElement#")>
</cfloop>
<cfset StructDelete(SESSION, "currentSoftware")>

I tried looping through the array, then referencing the the structure element using the code above but it always throws an error saying I can convert the reference to a number. Do I even have to worry about the deleting the structures or just delete the session array?
    This topic has been closed for replies.

    1 reply

    Inspiring
    October 15, 2008
    quote:

    Originally posted by: Ashburton
    I have an application where the use can step through a form to create a list of software. To make it easier reference the software name, ID and a few other fields are stored as a structure in each element of a one dimensional array like this:
    <cfset sDetails = StructNew()>
    <cfset sDetails.LicenceDetail_ID="">
    <cfset sDetails.SoftwareID="#FORM.softwareID#">
    <cfset sDetails.SoftwareName="#FORM.softwareName#">
    <cfset ArrayAppend(SESSION.SoftwareArray, sDetails)>

    My question is, how do I properly release this information from memory when I'm done with it? If it was a regular structure stored as a Session variable I would just delete it using this code.
    <cfloop index="ListElement" list="#StructKeyList(SESSION.currentSoftware)#" delimiters=",">
    <cfset StructDelete(SESSION.currentSoftware, "#ListElement#")>
    </cfloop>
    <cfset StructDelete(SESSION, "currentSoftware")>

    I tried looping through the array, then referencing the the structure element using the code above but it always throws an error saying I can convert the reference to a number. Do I even have to worry about the deleting the structures or just delete the session array?


    If this is a form page, why do you need arrays and structures to start with?