Thanks for the reply!  I'm definitely trying to get a handle on this as I don't 
want to chase down the repercussions in the future!  Thank so much for your 
help.  It almost makes sense to me now...


> > should I not worry about running 'createObject' on the same local.
> o_program structure member everytime? 
> 
> The fact that createObject is INSIDE the loop is precisely why it is
> working now and that is good.  When you posted your first "real" code
> sample (the second one) with the createObject outside the loop you 
> were
> only creating one instance of your CFC and reusing it over and over. 
> That is not what you wanted.  If you have 7 "programs", than you need 
> to
> create 7 objects.
> 
> > It's not completely obvious to me how 'local' magic is working. 
> 
> It's not magic really.  When you place anything (like a CFC) in the
> application scope it is shared by all running requests.  This is the
> same as a database table that is being used by several requests at 
> once.
 
> Changes made by one request will be visible to any other request
> looking in the table.  Think of a CFC in the application scope the 
> same
> way.  There are 3 main scopes in a CFC-- this, variables, and local. 
> This and variables are shared by everyone calling methods on that CFC. 
> 
> Local is specific to a particular method call.  If this still does 
> not
> make sense, PLEASE ask questions now and get it cleared up or you 
> will
> be asking for pain down the road when your app starts crashing under
> load due to concurrency issues because you didn't understand how to 
> make
> thread-safe singletons.  Print this off, read it, and post it on your
> cube wall: http://www.coldfusionjedi.com/downloads/cfcscopes.pdf
> 
> > And is there not a memory leak issue with running createObject on 
> every iteration? 
> 
> I'm not sure what you're asking here but the short answer is "no".  
> Now,
> creating objects DOES consume a nominal amount of memory-- this is 
> true,
> but that is not a "memory leak".  There was a recent memory leak 
> fixed
> in the  last cumulative hot fix for CF8 that had to do with placing 
> CFCs
> in shared scopes.  I don't see how it would affect your code, but if 
> you
> want to, you can install the hot fix.
> 
> > Should my previous version have worked? 
> 
> Which one?
 
> *The very first code you posted was somewhat usable.  It would have
> created a separate object for each record except for the fact that 
> you
> had some syntax errors [arrayNew()] and didn't locally var your
> variables.  
 
> *The second code sample you sent only used one program object and 
> still
> didn't use locally-scoped variables.  
 
> *Your third code sample is getting closer yet, but still not correct. 
> 
> You need to locally scope ALL VARIABLES THAT ARE SPECIFIC TO THAT 
> METHOD
> CALL.  This includes "q_programs".  Otherwise two people running this
> code at the exact same time will be sharing the exact same contents 
> of
> the q_programs variable since is in the variables scope by default.
> 
> > I don't mind doing this 'local' trick everywhere, but I am curious 
> about why the original wasn't working properly.
> 
> It's hard to say since your first code sample seemed to be
> altered-to-protect-the-innocent to the point that you significantly
> changed the flow of the code. However, I would guess that your first
> iteration of the code did not work because you were not creating a 
> new
> program object for every record in your result set.
> 
> One more thing, I would stay away from duplicating your CFCs.  It 
> might
> work in some scenarios, but duplicate is a deep-copy and that can 
> mean
> bad things if your CFC has references to a framework or some other
> complex variable that you do not actually wish to copy.
> 
> ~Brad
> 


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:329660
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