I would like to know how a cfc is instantiated in coldfusion under the hood !. I know you create an instance of the component and you will get a reference to the newly created instance and you can use it to call the public methods inside them.
But what exactly is happening when i write th code
<cfscript>
person = createObject('component','human') // what happen here!!!!
person.speak();
</cfscript>
Made some correction to my statement here!!!. the reason why i ask this question is because i have a instance stored in the application scope and the instance is used as below
application.person.speak();
now under very high load. i found that the memory is not release for the person obj and at some point it reached up to 200mb.. strange! . So made the correction as it says in best practices
request.person = duplicate(application.person);
now there is another direct way to do this is
request.person = createObject('component','human');
difference, the first one creates the object and keep it in share scope, do a deep copy to request everytime a request is made(here the instance is created only once). Second one does the instance creation every time the request is made. there is a performance difference between them for sure because in the second method the instance is created every time. I would like to know what exactly is the architecture behind creating an instance that makes it less better that the former!!
Just curies to know !
Coldfusion compiles into Java, and when you call the "createObject" function you are creating an instance of that class. Here are some links that might help explain a little more:
http://www.bennadel.com/blog/325-ColdFusion-CreateObject-vs-Java-NewInstance-.htm
http://blog.objectorientedcoldfusion.org/2009/07/16/coldfusion-9-object-creation-performance/