> But we're talking about a single request so if there is no garbage
> collection during a requests lifetime, being eligible or not makes no
> difference.

Right, but you could be storing the reference you create for a lot
longer than a single page request.

> Be that as it may, you're saying that the fact that a reference to the
> query is still in use, the query 'jumps' out of the UDF's local scope
> to live on in the requests memory.

The query itself, as an object on the heap, is never actually in the
function's local scope. Objects on the heap don't really have a scope.
References do, and the reference to that query that's declared in the
function's will be marked for deletion when the function finishes. The
query object itself will be marked for deletion when there are no more
references pointing to it.

> > References exist on the stack; the objects being referenced
> > exist in the heap.
>
> Can you expand a bit on what you're saying here?

Sure. If you create a query:

<cfquery name="foo" ...>
...
</cfquery>

what's actually happening there is that you've created two things -
the query itself, which is just an object with some stuff in it, and a
reference to that object, "foo".

So, then you do something like this:

<cfset bar = foo>

Now, you still have one query object, but two references to that
object: foo and bar.

Next, you do something like this:

<cfset structDelete(variables, "foo")>

Now, you still have the original query object, but only one reference
to it: bar. Since all this is happening in the span of a single page
request, it won't likely make any difference in memory consumption,
but you could just as easily create references in the Session,
Application or Server scopes and things would work the same way.

This concept of references on the stack vs objects in the heap is
common in many modern languages. Here's a description from the "Java
for ColdFusion Developers" book that came out a few years ago:

http://www.informit.com/articles/article.aspx?p=31755&seqNum=8

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/

Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online, or onsite.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:331522
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to