benphelps Posted March 17, 2009 Share Posted March 17, 2009 I have a script that runs as a cron job. It makes about 1500 runs a day, and loops about 60 times in each run. Is unset() worth using, or will it just increase the time it takes the job to do a loop? Quote Link to comment https://forums.phpfreaks.com/topic/149859-solved-unset-is-it-worth-it/ Share on other sites More sharing options...
samshel Posted March 17, 2009 Share Posted March 17, 2009 depends on where and how u r using it. All variables are automatically unset after the script ends. If you are overwriting and reusing variables and handle it efficiently then no need to unset, but if you referring them at many places and re-use or re-setting may cause confusion then unset() is safest.. As far as i know unset() will not slow down or fasten the speed as when u overwrite a variable it automatically gets unset first. Quote Link to comment https://forums.phpfreaks.com/topic/149859-solved-unset-is-it-worth-it/#findComment-786989 Share on other sites More sharing options...
benphelps Posted March 17, 2009 Author Share Posted March 17, 2009 I think I will use unset, there are a few places that a variable can be left in memory, and I'm almost sure unset will clean some memory, and a few variables could be holding anywhere from 1 byte to a few mb. Quote Link to comment https://forums.phpfreaks.com/topic/149859-solved-unset-is-it-worth-it/#findComment-787005 Share on other sites More sharing options...
MadTechie Posted March 17, 2009 Share Posted March 17, 2009 If you have a large variable that is no longer needed and your about to to set another large variable then yes its worth it for the memory.. it really does depend on the script but unsetting really to related to memory the cost of the CPU cycle to unset is normally worth the return in memory but if you have a single boolean variable it may not really be worth unsetting but if you have a image or large array then it is worth it.. Personally i only really unset the large variables, (of course their are exceptions) Quote Link to comment https://forums.phpfreaks.com/topic/149859-solved-unset-is-it-worth-it/#findComment-787114 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.