Don't think that using references will lower your RAM usage

Objects are always copied by reference in PHP 5, which means that copying even the most complex object is instantaneous and essentially free in terms of memory usage. Furthermore, PHP makes extensive use of "copy-on-write", which means taking ten copies of the same array is also free, because they all point to the same object. It's called "copy-on-write" because the minute one of the arrays change from the others, a full copy is made so the change is kept separate.

 

Next chapter: Be wary of garbage collection, part 1 >>

Previous chapter: Pre-increment where possible

Jump to:

 

Home: Table of Contents

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar