If gameObject is invisible - disable it... what's wrong with this code?

Hi everyone,

I am in the process of optimising my game. I have a script that turns off all of the onscreen objects’ behaviour if they are not visible in the renderer and it works great, but when I tried to add this script to actually disable any off screen objects, it just disables them all whether they are onscreen or not… what am I missing?

    function Update () 
{
 if (gameObject.renderer.isVisible)
 {
 gameObject.active = true;
 }
 else
 {
 gameObject.active = false;
 }
}

it’s probably this:

http://answers.unity3d.com/questions/41962/renderisvisible-returning-false-for-one-frame.html