Ask a Jedi: cfinvoke versus createObject

So I could have sworn I had blogged on this before, but I couldn’t find it in my archives, so here goes. (And if I do start repeating myself, let me know folks!)

Is there a reason to favor cfinvoke over cfobject? Does cfinvoke clean up after itself faster?

Technically you are comparing apples and oranges. The cfobject tag (and createObject function) are meant to create an instance of a CFC. The cfinvoke tag runs a method on a CFC. You can use createObject to both create a CFC and run a method:


<cfset foo = createObject("component", "president").init(42)>

But the same could be done with cfinvoke.


<cfinvoke component="president" method="init" id="42" returnVariable="foo">

I think you will find it comes down to a style issue.