3 Replies Latest reply on Oct 19, 2007 3:11 AM by John Mawer esq

    Destroying a CFC object

    John Mawer esq Level 1
      I'm new to CF OO, so apologies if this is dumb question.

      How do I destroy an object that has been made persistant by giving it application scope?

      Researching this I've found two things:

      - It's been suggested that I can set the object to Null using:

      <cfset objFoo = JavaCast( "null", 0 ) />

      This does seem to work but all the ColdFusion help documents say you should do this and it will cause unexpected results?

      - In other languages objects often have a finalizer method that can be called to destroy them, but I can't find a common approach to this in CF OO?
        • 1. Re: Destroying a CFC object
          Level 7
          CF CFC's are not that object orientated. They do not need to be
          specifically 'destroyed'. Clear all persistent variable references to
          an object and garbage collection will come along and remove them.

          So one just needs to set any persistent variable reference to the cfc to
          an empty string or any other value not pointing to the object.

          <cfset application.objFoo = "">

          Or of one wants a tiny bit more OO feel to it.

          <cfset structDelete(application, "objFoo">

          This comes form ColdFusion being a web application language. Do the the
          stateless nature of HTTP requests and responses, the default behavior of
          the application server is to destroy and clear all instance data at the
          end of the request, unless something has been done to persist it. Remove
          that connection to persistence and the data is thrown back into the
          recycling bin.

          • 2. Re: Destroying a CFC object
            Level 7
            CF CFC's are not that object orientated. They do not need to be
            specifically 'destroyed'. Clear all persistent variable references to
            an object and garbage collection will come along and remove them.

            So one just needs to set any persistent variable reference to the cfc to
            an empty string or any other value not pointing to the object.

            <cfset application.objFoo = "">

            Or if one wants a tiny bit more OO feel to it.

            <cfset structDelete(application, "objFoo">

            This comes from ColdFusion being a web application language. Do to the
            stateless nature of HTTP requests and responses, the default behavior of
            the application server is to destroy and clear all instance data at the
            end of the request, unless something has been done to persist it. Remove
            that connection to persistence and the data is thrown back into the
            recycling bin.

            • 3. Re: Destroying a CFC object
              John Mawer esq Level 1
              Cool - Much appreciated.