Skip to main content
Participant
October 18, 2007
Question

Destroying a CFC object

  • October 18, 2007
  • 2 replies
  • 2638 views
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?
This topic has been closed for replies.

2 replies

Inspiring
October 18, 2007
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.

Participant
October 19, 2007
Cool - Much appreciated.
Inspiring
October 18, 2007
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.