Working with beans: Should I unset them after using them?

But there’s a previous question… Which unsets on which beans, when?

If you have a bean variable you create yourself, you can do what you want with it, and needn’t bother about what happens next. You could tidy up and unset, but given the ephemerous nature of a PHP request, I doubt that is worth the effort, and I wonder if it could even be counter-productive, by triggering garbage-collection on a memory heap that is just about to be wiped clean anyway.

I think it’s worth unsetting when you are in long-lived operations, or in loops where memory consumption is an issue, or when you expect one of those situations to arise after what you’re doing, but still inside the same web-server request.

1 Like