Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by pretender · Feb 25, 2011 at 01:14 PM · arraymemoryclearleak

help with memory leak

first to clear something out, the function i wrote is probably not the best practice, but it was done fast and it works, but later i discovered that memory used increases every time i use this function...so i guess there is some kind of problem with arrays... can you help me out. memory used increases pretty fast it renders function useless....

here is the code:

//REMOVE ALL OBJECTS THAT ARE OUTSIDE CUT OFF DISTANCE function RemoveObjectsOutsideCutoffDistance(center : Vector3){

//ONLY REMOVE IF WE ARE IN NORMAL MODE if(currentViewState==viewState.normal || currentViewState==viewState.region){

var objectsToShow=new Array();

//GO THROUGH ALL SYSTEMS for(i=0;i<TrackingControl.Systems.length;i++){
//CHECK IF SYSTEM IS LOADED AND VISIBLE if(TrackingControl.Systems[i].isLoaded && TrackingControl.Systems[i].isVisible){
//GET THE COLLIDERS OF OBJECTS THAT ARE INSIDE THE SPHERE COLLIDER var colliders=Physics.OverlapSphere(center,TrackingControl.Systems[i].radius);

     //MAKE AN ARRAY OF OBJECTS THAT WE ARE GOING TO SHOW                
     for(var e=0;e&lt;colliders.length;e++){
         if(colliders[e].tag==TrackingControl.Systems[i].tag){
             if(!colliders[e].gameObject.GetComponent("Highlight").hidden){
                 objectsToShow.Push(colliders[e].transform);
             }
         }
     }

     //HIDE ALL OBJECTS IN THE SYSTEM
     var Objects : GameObject[]=GameObject.FindGameObjectsWithTag(TrackingControl.Systems[i].tag);
     for(k=0;k&lt;Objects.length;k++){
         Objects[k].renderer.enabled=false;
         Objects[k].gameObject.layer=2;
     }
 }       
     }

 //COPY "OBJECTS TO SHOW" INTO GLOBAL ARRAY THAT TRACKS VISIBLE OBJECTS IN THE SCENE
 //WE CAN USE THAT ARRAY TO HANDLE WHAT OBJECT TO SHOW WHEN IN HIDDEN MODE
 if(currentSeeThroughState==seeThroughState.hidden){
     visibleObjects=objectsToShow;
 }

 //UNHIDE THE ONES THAT ARE INSIDE THE SPHERE
 for(j=0;j&lt;objectsToShow.length;j++){
     if(!objectsToShow[j].gameObject.GetComponent("Highlight").hidden){
         objectsToShow[j].renderer.enabled=true;
         objectsToShow[j].gameObject.layer=0;
         RemoveHighlight(objectsToShow[j].transform);
     }
 }

}

}

what is happening here is that i want to remove all objects from the scene that are not inside the sphere that has radius determined in other script. so i get all objects (from different systems in the scene- tracking control) that are in the sphere, copy all the objects in the array objectsToShow, then hide all objects in the scene and then unhide that ones that are in the objectsToShow. There is also a case where we copy that array to other global array, but that is irrelevant now, since memory goes up when we are outside that state.

it works fine but only things that worries me is that memory leaks....i do not know why, do i need to clear arrays? they should be alive only inside the function.

thanks in advance! any help appreciated!

cross post to forums: http://forum.unity3d.com/threads/79548-problem-with-memory-leak..-please-help-me-solve-it

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by efge · Feb 25, 2011 at 02:30 PM

You want to not render objects outside a given distance/radius?

Why not use the farClipPlane of your Camera for all objects or layerCullDistances for several objects assigned to layers?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pretender · Feb 25, 2011 at 04:35 PM 0
Share

because i want to remove object that are outside of sphere radius which is in the center of current selection not camera

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Mesh memory leak 3 Answers

Default-Diffuse material leak - how to find source? 2 Answers

Laggy gameplay and occasional crashes 1 Answer

Unable to free resources from memory 0 Answers

Why does Unity's memory usage increase continuously while the profiler reports static usage? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges