Unity Pro Water memory usage

I put two Pro water objects (with refraction) into my scene. Because I noted that the Water script is running constantly, sucking CPU even when you’re far away from it, I use a collider to enable both the water script and the water renderer only when the player is within sight of the water object.

Here’s my collider script:

private var theRenderer : Renderer;
private var water : Water;

// most important to turn off the water script when not in the area since it chews up CPU when active
function Start ()
{
	theRenderer = gameObject.GetComponent(Renderer);
	water = gameObject.GetComponent(Water);
	theRenderer.enabled = false;
	water.enabled = false;
}

function OnTriggerEnter( coll : Collider )
{
		theRenderer.enabled = true;
		water.enabled = true;	
}

function OnTriggerExit( coll : Collider )
{   
		theRenderer.enabled = false;
		water.enabled = false;	
}

But now it appears that enabling and disabling the Water script and renderer eats RAM – it seems to add about 15-20MB of memory each time I enter and leave the water collider. Unlike when other objects are instantiated and destroyed, this added memory is never recovered, so the RAM of the player just climbs and climbs.

I observe this with an OSX standalone via Activity Monitor.

Obviously this is bad news. Any ideas?

Just a guess, but since the pro water uses render texture(s), maybe they don’t get destroyed automatically. Try killing them manually and see what happens?

A valid guess, but if you check Water.cs you’ll see they get destroyed in OnDisable().

I don’t know what’s going on either, though. :slight_smile:

Cheers,
-Jon

Thanks for the ideas. I did a test where I put just my water with that script in it in a test scene, and in that case, starting and stopping the water script doesn’t add any memory at all. So there’s either something else going on entirely, or it’s interacting oddly with other components in the scene.

But it’s not a basic fault in the water script.

Update:

There is a bug causes the memory leak when the water object is on a terrain object, but not on a regular mesh.

Submitted as case #18531.