I think I know the answer to this but I wanted to verify with the experts.

When you create a variable on a page, it lives until the request is 
complete, right?

And since coldfusion string variables are java string objects... they're 
immutable, and thus every time you "change" a variable, it creates a new 
variable.

Take the following code for example:

<cfset foo = "1234567890">
<cfset foo = "0123456789">
<cfset foo = "9012345678">
<cfset foo = "8901234567">
<cfset foo = "7890123456">
<cfset foo = "6789012345">

Even though we appear to be changing the same variable, we're actually 
creating new string objects in java, and the previous versions of "foo" 
all remain in memory until the request ends.

Here's a practical example.  Let's pretend I've got an email to send to 
10,000 people.  Each copy of the email is personalized, like follows:

<cfset content = "Dear <UUID>, pretend this message is 2048 characters 
in length.">
<cfloop from="1" to="10000" step="1" index="cnt">
        <cfset content = replace(content,"<UUID>",CreateUUID(),"ALL")>
        <cfmail ... >#content#</cfmail>
</cfloop>

So now, assuming each message is approximately 2048 characters in length 
(2k), by the time the request ends, I've got 10,000 copies of "content" 
in memory, 2k each, taking up 20,000k (20MB) of RAM.

Is that right, or close?

Rick

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:259076
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to