Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity Pro Water memory usage

Discussion in 'Editor & General Support' started by DocSWAB, Feb 14, 2008.

  1. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    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:
    Code (csharp):
    1. private var theRenderer : Renderer;
    2. private var water : Water;
    3.  
    4. // most important to turn off the water script when not in the area since it chews up CPU when active
    5. function Start ()
    6. {
    7.     theRenderer = gameObject.GetComponent(Renderer);
    8.     water = gameObject.GetComponent(Water);
    9.     theRenderer.enabled = false;
    10.     water.enabled = false;
    11. }
    12.  
    13. function OnTriggerEnter( coll : Collider )
    14. {
    15.         theRenderer.enabled = true;
    16.         water.enabled = true;  
    17. }
    18.  
    19. function OnTriggerExit( coll : Collider )
    20. {  
    21.         theRenderer.enabled = false;
    22.         water.enabled = false; 
    23. }
    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?
     
  2. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    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?
     
  3. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    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. :)

    Cheers,
    -Jon
     
  4. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    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.
     
  5. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    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.