Does PHP support the RAII pattern? How?

前端 未结 4 1233
挽巷
挽巷 2020-12-17 16:34

Most resources on PHP never touch memory management because the language itself is pretty good at doing this for you. However, in PHP you often end up dealing with external

4条回答
  •  不思量自难忘°
    2020-12-17 16:54

    PHP uses reference counting, so when you're done with a variable it gets cleaned up immediately. (Unless you create cycles.) That frees up resources promptly so you generally don't need to worry about explicit resource management beyond being careful to not create memory cycles.

    If you did want to implement any particular strategy, you can do it by making sure that the resource is only used by one variable. Whenever that variable is pointed away from the resource, the resource should be immediately freed up.

提交回复
热议问题