We all know php's variables(array, integer,string) would be taking large memory. So PHP recommend to unset the variables to optimize the memory.

Should I do that in Drupal too ? or Is Drupal internally handling such a things ?

| improve this question | | | | |
  • So PHP recommend to unset the variables where have you found this recommendation? – Letharion Jun 11 '15 at 6:38

No, Drupal is not doing anything to handle this; the very fact you're asking might suggest you're not totally sure how this works, as Drupal has no power over the efficiency of the code you write.

GC runs every time a function finishes, so unless you've identified an actual problem in one specific function, clearing up every single variable after you've used it, even though you theoretically can, would surely be considered premature optimisation.

Bottom line: Drupal cannot help you to write efficient code, you need to apply what you know from PHP. Whether you want or need to free the memory for every single variable manually depends on your requirements and specific code.

I would personally say you're over-thinking this a bit, as in an ideal world your functions should be small and modularised enough for this not to be an issue anyway. React to real problems, not perceived or potential ones, when it comes to optimisation.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.