CodeIgniter Forums
Object destruction - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Object destruction (/showthread.php?tid=19813)



Object destruction - El Forum - 06-19-2009

[eluser]steveeakin[/eluser]
Does CI handle the destruction of objects or does it let PHP's garbage collector take care of it?

If CI handles it, when and where does it go?


Object destruction - El Forum - 06-19-2009

[eluser]TheFuzzy0ne[/eluser]
As far as I am aware, the destruction of objects is left to PHP's garbage collection process.


Object destruction - El Forum - 06-19-2009

[eluser]Dam1an[/eluser]
I agree with Fuzz... It makes sense to leave it up to PHP, as it just gets rid of everything when the script terminates, where as CI would need to keep track of what gets used where, and it doesn't know if something would be used later on etc

I think the only 'clean up' CI does is close the database connection if it exists at the end


Object destruction - El Forum - 06-19-2009

[eluser]steveeakin[/eluser]
Than you all for the replies. I was hoping there would be a model destruction when the view is called since at that point, it should be done. It is pretty insignificant, but would have given one more detail in the benchmarking department (from construction to destruction of a model.)


Object destruction - El Forum - 06-19-2009

[eluser]Dam1an[/eluser]
Well, you can always create a __destruct method (maybe to MY_Controller and MY_Model) so if you start a timer in the constructor and stop it in the destructor, you know how much time was spent in that model


Object destruction - El Forum - 06-19-2009

[eluser]steveeakin[/eluser]
[quote author="Dam1an" date="1245444627"]Well, you can always create a __destruct method (maybe to MY_Controller and MY_Model) so if you start a timer in the constructor and stop it in the destructor, you know how much time was spent in that model[/quote]

That is the way I have it set up now, but it could be a pain for every developer to have to do that in every controller that uses a model. Even if its one line of code, its hard to manage with multiple people.


Object destruction - El Forum - 06-19-2009

[eluser]Dam1an[/eluser]
Thats why I said put it in the parent Controller/Model, then you only do it once, and it takes care of itself assuming you extend the new parent object instead of the CI parent